public override void Calculate(SlotTypes slotType)
{
// Reading the parameters
MAMethod maMethod = (MAMethod)IndParam.ListParam[1].Index;
int period = (int)IndParam.NumParam[0].Value;
int prev = IndParam.CheckParam[0].Checked ? 1 : 0;
// Calculation
int firstBar = period + 2;
double[] DIPos = new double[Bars];
double[] DINeg = new double[Bars];
for (int bar = 1; bar < Bars; bar++)
{
double trueRange = Math.Max(High[bar], Close[bar - 1]) - Math.Min(Low[bar], Close[bar - 1]);
if (trueRange < Point)
trueRange = Point;
double deltaHigh = High[bar] - High[bar - 1];
double deltaLow = Low[bar - 1] - Low[bar];
if (deltaHigh > 0 && deltaHigh > deltaLow)
DIPos[bar] = 100 * deltaHigh / trueRange;
else
DIPos[bar] = 0;
if (deltaLow > 0 && deltaLow > deltaHigh)
DINeg[bar] = 100 * deltaLow / trueRange;
else
DINeg[bar] = 0;
}
double[] ADIPos = MovingAverage(period, 0, maMethod, DIPos);
double[] ADINeg = MovingAverage(period, 0, maMethod, DINeg);
double[] ADIOsc = new double[Bars];
for (int bar = 0; bar < Bars; bar++)
ADIOsc[bar] = ADIPos[bar] - ADINeg[bar];
// Saving the components
Component = new IndicatorComp[4];
Component[0] = new IndicatorComp();
Component[0].CompName = "The ADI+";
Component[0].DataType = IndComponentType.IndicatorValue;
Component[0].ChartType = IndChartType.Line;
Component[0].ChartColor = Color.Green;
Component[0].FirstBar = firstBar;
Component[0].Value = ADIPos;
Component[1] = new IndicatorComp();
Component[1].CompName = "The ADI-";
Component[1].DataType = IndComponentType.IndicatorValue;
Component[1].ChartType = IndChartType.Line;
Component[1].ChartColor = Color.Red;
Component[1].FirstBar = firstBar;
Component[1].Value = ADINeg;
Component[2] = new IndicatorComp();
Component[2].ChartType = IndChartType.NoChart;
Component[2].FirstBar = firstBar;
Component[2].Value = new double[Bars];
Component[3] = new IndicatorComp();
Component[3].ChartType = IndChartType.NoChart;
Component[3].FirstBar = firstBar;
Component[3].Value = new double[Bars];
// Sets the Component's type
if (slotType == SlotTypes.OpenFilter)
{
Component[2].DataType = IndComponentType.AllowOpenLong;
Component[2].CompName = "Is long entry allowed";
Component[3].DataType = IndComponentType.AllowOpenShort;
Component[3].CompName = "Is short entry allowed";
}
else if (slotType == SlotTypes.CloseFilter)
{
Component[2].DataType = IndComponentType.ForceCloseLong;
Component[2].CompName = "Close out long position";
Component[3].DataType = IndComponentType.ForceCloseShort;
Component[3].CompName = "Close out short position";
}
switch (IndParam.ListParam[0].Text)
{
case "The ADI+ rises":
OscillatorLogic(firstBar, prev, ADIPos, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_rises);
break;
case "The ADI+ falls":
OscillatorLogic(firstBar, prev, ADIPos, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_falls);
break;
case "The ADI- rises":
OscillatorLogic(firstBar, prev, ADINeg, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_rises);
break;
case "The ADI- falls":
OscillatorLogic(firstBar, prev, ADINeg, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_falls);
break;
case "The ADI+ is higher than ADI-":
OscillatorLogic(firstBar, prev, ADIOsc, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_is_higher_than_the_level_line);
break;
case "The ADI+ is lower than ADI-":
OscillatorLogic(firstBar, prev, ADIOsc, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_is_lower_than_the_level_line);
break;
case "The ADI+ crosses the ADI- line upward":
OscillatorLogic(firstBar, prev, ADIOsc, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_crosses_the_level_line_upward);
break;
case "The ADI+ crosses the ADI- line downward":
OscillatorLogic(firstBar, prev, ADIOsc, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_crosses_the_level_line_downward);
break;
case "The ADI+ changes its direction upward":
OscillatorLogic(firstBar, prev, ADIPos, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_changes_its_direction_upward);
break;
case "The ADI+ changes its direction downward":
OscillatorLogic(firstBar, prev, ADIPos, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_changes_its_direction_downward);
break;
case "The ADI- changes its direction upward":
OscillatorLogic(firstBar, prev, ADINeg, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_changes_its_direction_upward);
break;
case "The ADI- changes its direction downward":
OscillatorLogic(firstBar, prev, ADINeg, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_changes_its_direction_downward);
break;
default:
break;
}
return;
}