ATAS.Indicators
Calculation of Indicators Based on Other Indicators

To generate an indicator based on another indicator, create and calculate the indicator based on which the payment will be made, and then use its value in your own calculations. Example of the implementation of the MACD indicator

public class MACD : Indicator
{
private readonly EMA _long = new EMA();
private readonly EMA _short = new EMA();
private readonly SMA _sma = new SMA();
public int LongPeriod
{
get { return _long.Period; }
set
{
if (value <= 0)
return;
_long.Period = value;
RecalculateValues();
}
}
public int ShortPeriod
{
get { return _short.Period; }
set
{
if (value <= 0)
return;
_short.Period = value;
RecalculateValues();
}
}
public int SignalPeriod
{
get { return _sma.Period; }
set
{
if (value <= 0)
return;
_sma.Period = value;
RecalculateValues();
}
}
public MACD()
{
Panel = IndicatorDataProvider.NewPanel;
((ValueDataSeries)DataSeries[0]).VisualType = VisualMode.Histogram;
((ValueDataSeries)DataSeries[0]).Color = Colors.CadetBlue;
DataSeries.Add(new ValueDataSeries("Signal")
{
VisualType = VisualMode.Line,
});
LongPeriod = 26;
ShortPeriod = 12;
SignalPeriod = 9;
}
protected override void OnCalculate(int bar, decimal value)
{
var macd =_short.Calculate(bar, value) - _long.Calculate(bar, value);
var signal = _sma.Calculate(bar, macd);
this[bar] = macd;
DataSeries[1][bar] = signal;
}
}