Add DOSC - Derivative Oscillator

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/mihakralj/QuanTAlib?shareId=XXXX-XXXX-XXXX-XXXX).
This commit is contained in:
Miha Kralj
2024-11-04 14:28:47 -08:00
parent c622b0e2d3
commit c58a054a28
5 changed files with 435 additions and 344 deletions
+74
View File
@@ -0,0 +1,74 @@
using System.Runtime.CompilerServices;
namespace QuanTAlib;
/// <summary>
/// DOSC: Derivative Oscillator
/// A momentum indicator that combines the Relative Strength Index (RSI) and the Moving Average Convergence Divergence (MACD) to identify potential trend reversals.
/// </summary>
/// <remarks>
/// The DOSC calculation process:
/// 1. Calculate the RSI
/// 2. Calculate the MACD of the RSI
/// 3. Calculate the signal line (SMA) of the MACD
/// 4. Subtract the signal line from the MACD to get the DOSC
///
/// Key characteristics:
/// - Combines RSI and MACD
/// - Oscillates above and below zero
/// - Positive values indicate bullish momentum
/// - Negative values indicate bearish momentum
/// - Crosses above zero suggest buying opportunities
/// - Crosses below zero suggest selling opportunities
///
/// Formula:
/// DOSC = MACD(RSI) - Signal(MACD(RSI))
///
/// Sources:
/// Original development
/// https://www.investopedia.com/terms/d/derivativeoscillator.asp
/// </remarks>
[SkipLocalsInit]
public sealed class Dosc : AbstractBase
{
private readonly Rsi _rsi;
private readonly Macd _macd;
private readonly Sma _signal;
/// <param name="source">The data source object that publishes updates.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Dosc(object source) : this()
{
var pubEvent = source.GetType().GetEvent("Pub");
pubEvent?.AddEventHandler(source, new BarSignal(Sub));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Dosc()
{
_rsi = new Rsi();
_macd = new Macd();
_signal = new Sma(9);
WarmupPeriod = 34; // RSI requires 14 periods + MACD requires 26 periods + 9 for signal line
Name = "DOSC";
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override void ManageState(bool isNew)
{
if (isNew)
{
_index++;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override double Calculation()
{
ManageState(BarInput.IsNew);
var rsi = _rsi.Calc(BarInput.Close, BarInput.IsNew);
var macd = _macd.Calc(rsi, BarInput.IsNew);
_signal.Calc(macd, BarInput.IsNew);
return macd - _signal.Value;
}
}
+32 -32
View File
@@ -1,32 +1,32 @@
# Oscillators indicators
Done: 20, Todo: 9
✔️ AC - Acceleration Oscillator
✔️ AO - Awesome Oscillator
✔️ AROON - Aroon oscillator (Up, Down)
✔️ BOP - Balance of Power
✔️ CCI - Commodity Channel Index
✔️ CFO - Chande Forcast Oscillator
✔️ CHOP - Choppiness Index
✔️ CMO - Chande Momentum Oscillator
✔️ COG - Ehler's Center of Gravity
✔️ COPPOCK - Coppock Curve
✔️ CRSI - Connor RSI
CTI - Ehler's Correlation Trend Indicator
DOSC - Derivative Oscillator
EFI - Elder Ray's Force Index
FISHER - Fisher Transform
FOSC - Forecast Oscillator
*GATOR - Williams Alliator Oscillator (Upper Jaw, Lower Jaw, Teeth)
*KDJ - KDJ Indicator (K, D, J lines)
KRI - Kairi Relative Index
✔️ RSI - Relative Strength Index
✔️ RSX - Jurik Trend Strength Index
*RVGI - Relative Vigor Index (RVGI, Signal)
✔️ SMI - Stochastic Momentum Index
✔️ SRSI - Stochastic RSI (SRSI, Signal)
✔️ STC - Schaff Trend Cycle
✔️ STOCH - Stochastic Oscillator (%K, %D)
✔️ TSI - True Strength Index
✔️ UO - Ultimate Oscillator
✔️ WILLR - Larry Williams' %R
# Oscillators indicators
Done: 21, Todo: 8
✔️ AC - Acceleration Oscillator
✔️ AO - Awesome Oscillator
✔️ AROON - Aroon oscillator (Up, Down)
✔️ BOP - Balance of Power
✔️ CCI - Commodity Channel Index
✔️ CFO - Chande Forcast Oscillator
✔️ CHOP - Choppiness Index
✔️ CMO - Chande Momentum Oscillator
✔️ COG - Ehler's Center of Gravity
✔️ COPPOCK - Coppock Curve
✔️ CRSI - Connor RSI
CTI - Ehler's Correlation Trend Indicator
✔️ DOSC - Derivative Oscillator
EFI - Elder Ray's Force Index
FISHER - Fisher Transform
FOSC - Forecast Oscillator
*GATOR - Williams Alliator Oscillator (Upper Jaw, Lower Jaw, Teeth)
*KDJ - KDJ Indicator (K, D, J lines)
KRI - Kairi Relative Index
✔️ RSI - Relative Strength Index
✔️ RSX - Jurik Trend Strength Index
*RVGI - Relative Vigor Index (RVGI, Signal)
✔️ SMI - Stochastic Momentum Index
✔️ SRSI - Stochastic RSI (SRSI, Signal)
✔️ STC - Schaff Trend Cycle
✔️ STOCH - Stochastic Oscillator (%K, %D)
✔️ TSI - True Strength Index
✔️ UO - Ultimate Oscillator
✔️ WILLR - Larry Williams' %R