Description
The Disparity Index indicator is used to define price reversal levels.
The histogram bars (disparity index) when rising above the upper band, the overbought level is reached.
The histogram bars when decreasing below the lower band, the oversold level is reached.
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Levels(0)]
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class mDisparityIndex : Indicator
{
[Parameter("Periods (10)", DefaultValue = 10, Group = "DisparityIndex")]
public int inpPeriods { get; set; }
[Parameter("Levels Coefficients (2.618)", DefaultValue = 2.618, Group = "DisparityIndex")]
public double inpLevelsCoefficients { get; set; }
[Parameter("Smooth Type (sma)", DefaultValue = MovingAverageType.Simple, Group = "DisparityIndex")]
public MovingAverageType inpSmoothType { get; set; }
[Output("Disparity Index", LineColor = "Transparent", LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries outDisparityIndex { get; set; }
[Output("Band Up", LineColor = "Black", LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries outDisparityIndexUp { get; set; }
[Output("Band Down", LineColor = "Black", LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries outDisparityIndexDown { get; set; }
[Output("Histogram Up", PlotType = PlotType.Histogram, LineColor = "Green", Thickness = 3)]
public IndicatorDataSeries outDisparityIndexUpC { get; set; }
[Output("Histogram Down", PlotType = PlotType.Histogram, LineColor = "Red", Thickness = 3)]
public IndicatorDataSeries outDisparityIndexDnC { get; set; }
private IndicatorDataSeries _absroc, _di;
private MovingAverage _maprice, _maabsroc;
protected override void Initialize()
{
_absroc = CreateDataSeries();
_di = CreateDataSeries();
_maprice = Indicators.MovingAverage(Bars.ClosePrices, inpPeriods, inpSmoothType);
_maabsroc = Indicators.MovingAverage(_absroc, inpPeriods, inpSmoothType);
}
public override void Calculate(int i)
{
_absroc[i] = Math.Abs(Bars.ClosePrices[i] - Bars.ClosePrices[i - 1]) / Bars.ClosePrices[i] * 100;
_di[i] = 100 * (Bars.ClosePrices[i] - _maprice.Result[i]) / (_maprice.Result[i]);
outDisparityIndex[i] = _di[i];
outDisparityIndexUp[i] = _maabsroc.Result[i] * inpLevelsCoefficients;
outDisparityIndexDown[i] = -_maabsroc.Result[i] * inpLevelsCoefficients;
if (!double.IsNaN(_di[i]))
{
if (_di[i] > 0)
{
outDisparityIndexUpC[i] = _di[i];
outDisparityIndexDnC[i] = double.NaN;
}
else
{
outDisparityIndexUpC[i] = double.NaN;
outDisparityIndexDnC[i] = _di[i];
}
}
else
{
outDisparityIndexUpC[i] = double.NaN;
outDisparityIndexDnC[i] = double.NaN;
}
}
}
}

mfejza
Joined 25.01.2022
- Type: Free
- Language: C#
- Trading Platform: cTrader Automate
- Filename: mDisparityIndex.algo
- Rating: 5
- Installs: 853
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Comments
Only logged in users can post a comment
Comments not found