public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters var period1 = (int) IndParam.NumParam[0].Value; var period2 = (int) IndParam.NumParam[1].Value; int prvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int firstBar = period1 + period2 + 2; var adOscillator = new double[Bars]; // --------------------------------------------------------- var obos1 = new OverboughtOversoldIndex(); obos1.Initialize(SlotType); obos1.IndParam.NumParam[0].Value = IndParam.NumParam[0].Value; obos1.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked; obos1.Calculate(DataSet); var obos2 = new OverboughtOversoldIndex(); obos2.Initialize(SlotType); obos2.IndParam.NumParam[0].Value = IndParam.NumParam[1].Value; obos2.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked; obos2.Calculate(DataSet); double[] adIndicator1 = obos1.Component[0].Value; double[] adIndicator2 = obos2.Component[0].Value; // ---------------------------------------------------------- for (int bar = firstBar; bar < Bars; bar++) { adOscillator[bar] = adIndicator1[bar] - adIndicator2[bar]; } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp { CompName = "Histogram", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Histogram, FirstBar = firstBar, Value = adOscillator }; Component[1] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = new double[Bars] }; Component[2] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = new double[Bars] }; // Sets the Component's type if (SlotType == SlotTypes.OpenFilter) { Component[1].DataType = IndComponentType.AllowOpenLong; Component[1].CompName = "Is long entry allowed"; Component[2].DataType = IndComponentType.AllowOpenShort; Component[2].CompName = "Is short entry allowed"; } else if (SlotType == SlotTypes.CloseFilter) { Component[1].DataType = IndComponentType.ForceCloseLong; Component[1].CompName = "Close out long position"; Component[2].DataType = IndComponentType.ForceCloseShort; Component[2].CompName = "Close out short position"; } // Calculation of the logic var indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "Oscillator rises": indLogic = IndicatorLogic.The_indicator_rises; break; case "Oscillator falls": indLogic = IndicatorLogic.The_indicator_falls; break; case "Oscillator is higher than the zero line": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; break; case "Oscillator is lower than the zero line": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; break; case "Oscillator crosses the zero line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; break; case "Oscillator crosses the zero line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; break; case "Oscillator changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; break; case "Oscillator changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; break; } OscillatorLogic(firstBar, prvs, adOscillator, 0, 0, ref Component[1], ref Component[2], indLogic); }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters int previous = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation var oscillator = new double[Bars]; // --------------------------------------------------------- var obos1 = new OverboughtOversoldIndex(); obos1.Initialize(SlotType); obos1.IndParam.NumParam[0].Value = IndParam.NumParam[0].Value; obos1.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked; obos1.Calculate(DataSet); var obos2 = new OverboughtOversoldIndex(); obos2.Initialize(SlotType); obos2.IndParam.NumParam[0].Value = IndParam.NumParam[1].Value; obos2.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked; obos2.Calculate(DataSet); double[] indicator1 = obos1.Component[0].Value; double[] indicator2 = obos2.Component[0].Value; // ---------------------------------------------------------- int firstBar = 0; for (int c = 0; c < obos1.Component.Length; c++) { if (firstBar < obos1.Component[c].FirstBar) { firstBar = obos1.Component[c].FirstBar; } if (firstBar < obos2.Component[c].FirstBar) { firstBar = obos2.Component[c].FirstBar; } } firstBar += 3; for (int bar = firstBar; bar < Bars; bar++) { oscillator[bar] = indicator1[bar] - indicator2[bar]; } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp { CompName = "Histogram", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Histogram, FirstBar = firstBar, Value = oscillator }; Component[1] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = new double[Bars] }; Component[2] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = new double[Bars] }; // Sets the Component's type if (SlotType == SlotTypes.OpenFilter) { Component[1].DataType = IndComponentType.AllowOpenLong; Component[1].CompName = "Is long entry allowed"; Component[2].DataType = IndComponentType.AllowOpenShort; Component[2].CompName = "Is short entry allowed"; } else if (SlotType == SlotTypes.CloseFilter) { Component[1].DataType = IndComponentType.ForceCloseLong; Component[1].CompName = "Close out long position"; Component[2].DataType = IndComponentType.ForceCloseShort; Component[2].CompName = "Close out short position"; } // Calculation of the logic var logicRule = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "Oscillator rises": logicRule = IndicatorLogic.The_indicator_rises; break; case "Oscillator falls": logicRule = IndicatorLogic.The_indicator_falls; break; case "Oscillator is higher than the zero line": logicRule = IndicatorLogic.The_indicator_is_higher_than_the_level_line; break; case "Oscillator is lower than the zero line": logicRule = IndicatorLogic.The_indicator_is_lower_than_the_level_line; break; case "Oscillator crosses the zero line upward": logicRule = IndicatorLogic.The_indicator_crosses_the_level_line_upward; break; case "Oscillator crosses the zero line downward": logicRule = IndicatorLogic.The_indicator_crosses_the_level_line_downward; break; case "Oscillator changes its direction upward": logicRule = IndicatorLogic.The_indicator_changes_its_direction_upward; break; case "Oscillator changes its direction downward": logicRule = IndicatorLogic.The_indicator_changes_its_direction_downward; break; } OscillatorLogic(firstBar, previous, oscillator, 0, 0, ref Component[1], ref Component[2], logicRule); }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; var maSignalMAMethod = (MAMethod)IndParam.ListParam[2].Index; // Reading the parameters var period1 = (int)IndParam.NumParam[0].Value; var period2 = (int)IndParam.NumParam[1].Value; int prvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int firstBar = period1 + period2 + 2; var adOscillator = new double[Bars]; // --------------------------------------------------------- var obos1 = new OverboughtOversoldIndex(); obos1.Initialize(SlotType); obos1.IndParam.NumParam[0].Value = IndParam.NumParam[0].Value; obos1.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked; obos1.Calculate(DataSet); double[] adIndicator1 = obos1.Component[0].Value; double[] adIndicator2 = MovingAverage(period2, 0, maSignalMAMethod, adIndicator1); // ---------------------------------------------------------- for (int bar = firstBar; bar < Bars; bar++) { adOscillator[bar] = adIndicator1[bar] - adIndicator2[bar]; } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp { CompName = "Histogram", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Histogram, FirstBar = firstBar, Value = adOscillator }; Component[1] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = new double[Bars] }; Component[2] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = new double[Bars] }; // Sets the Component's type if (SlotType == SlotTypes.OpenFilter) { Component[1].DataType = IndComponentType.AllowOpenLong; Component[1].CompName = "Is long entry allowed"; Component[2].DataType = IndComponentType.AllowOpenShort; Component[2].CompName = "Is short entry allowed"; } else if (SlotType == SlotTypes.CloseFilter) { Component[1].DataType = IndComponentType.ForceCloseLong; Component[1].CompName = "Close out long position"; Component[2].DataType = IndComponentType.ForceCloseShort; Component[2].CompName = "Close out short position"; } // Calculation of the logic var indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "Oscillator rises": indLogic = IndicatorLogic.The_indicator_rises; break; case "Oscillator falls": indLogic = IndicatorLogic.The_indicator_falls; break; case "Oscillator is higher than the zero line": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; break; case "Oscillator is lower than the zero line": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; break; case "Oscillator crosses the zero line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; break; case "Oscillator crosses the zero line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; break; case "Oscillator changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; break; case "Oscillator changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; break; } OscillatorLogic(firstBar, prvs, adOscillator, 0, 0, ref Component[1], ref Component[2], indLogic); }