public override void Calculate(IDataSet dataSet) { DataSet = dataSet; var macd1 = new MACD(); macd1.Initialize(SlotType); macd1.IndParam.ListParam[1].Index = IndParam.ListParam[1].Index; macd1.IndParam.ListParam[2].Index = IndParam.ListParam[2].Index; macd1.IndParam.ListParam[3].Index = IndParam.ListParam[3].Index; macd1.IndParam.NumParam[0].Value = IndParam.NumParam[0].Value; macd1.IndParam.NumParam[1].Value = IndParam.NumParam[2].Value; macd1.IndParam.NumParam[2].Value = IndParam.NumParam[4].Value; macd1.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked; macd1.Calculate(DataSet); var macd2 = new MACD(); macd2.Initialize(SlotType); macd2.IndParam.ListParam[1].Index = IndParam.ListParam[1].Index; macd2.IndParam.ListParam[2].Index = IndParam.ListParam[2].Index; macd2.IndParam.ListParam[3].Index = IndParam.ListParam[3].Index; macd2.IndParam.NumParam[0].Value = IndParam.NumParam[1].Value; macd2.IndParam.NumParam[1].Value = IndParam.NumParam[3].Value; macd2.IndParam.NumParam[2].Value = IndParam.NumParam[5].Value; macd2.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked; macd2.Calculate(DataSet); // Calculation int previous = IndParam.CheckParam[0].Checked ? 1 : 0; var period1 = (int) IndParam.NumParam[0].Value; var period2 = (int) IndParam.NumParam[1].Value; int firstBar = period1 + period2 + 2; double[] adIndicator1; double[] adIndicator2; switch (IndParam.ListParam[4].Index) { case 0: adIndicator1 = macd1.Component[0].Value; adIndicator2 = macd2.Component[0].Value; break; case 1: adIndicator1 = macd1.Component[1].Value; adIndicator2 = macd2.Component[1].Value; break; default: adIndicator1 = macd1.Component[2].Value; adIndicator2 = macd2.Component[2].Value; break; } var adOscillator = new double[Bars]; 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 = "Oscillator", 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 of MACD rises": indLogic = IndicatorLogic.The_indicator_rises; break; case "Oscillator of MACD falls": indLogic = IndicatorLogic.The_indicator_falls; break; case "Oscillator of MACD is higher than the zero line": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; break; case "Oscillator of MACD is lower than the zero line": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; break; case "Oscillator of MACD crosses the zero line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; break; case "Oscillator of MACD crosses the zero line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; break; case "Oscillator of MACD changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; break; case "Oscillator of MACD changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; break; } OscillatorLogic(firstBar, previous, adOscillator, 0, 0, ref Component[1], ref Component[2], indLogic); }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; var macd1 = new MACD(); macd1.Initialize(SlotType); macd1.IndParam.ListParam[1].Index = IndParam.ListParam[1].Index; macd1.IndParam.ListParam[2].Index = IndParam.ListParam[2].Index; macd1.IndParam.ListParam[3].Index = IndParam.ListParam[3].Index; macd1.IndParam.NumParam[0].Value = IndParam.NumParam[0].Value; macd1.IndParam.NumParam[1].Value = IndParam.NumParam[2].Value; macd1.IndParam.NumParam[2].Value = IndParam.NumParam[4].Value; macd1.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked; macd1.Calculate(DataSet); var macd2 = new MACD(); macd2.Initialize(SlotType); macd2.IndParam.ListParam[1].Index = IndParam.ListParam[1].Index; macd2.IndParam.ListParam[2].Index = IndParam.ListParam[2].Index; macd2.IndParam.ListParam[3].Index = IndParam.ListParam[3].Index; macd2.IndParam.NumParam[0].Value = IndParam.NumParam[1].Value; macd2.IndParam.NumParam[1].Value = IndParam.NumParam[3].Value; macd2.IndParam.NumParam[2].Value = IndParam.NumParam[5].Value; macd2.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked; macd2.Calculate(DataSet); // Calculation int previous = IndParam.CheckParam[0].Checked ? 1 : 0; double[] adIndicator1; double[] adIndicator2; switch (IndParam.ListParam[4].Index) { case 0: adIndicator1 = macd1.Component[0].Value; adIndicator2 = macd2.Component[0].Value; break; case 1: adIndicator1 = macd1.Component[1].Value; adIndicator2 = macd2.Component[1].Value; break; default: adIndicator1 = macd1.Component[2].Value; adIndicator2 = macd2.Component[2].Value; break; } int firstBar = 0; for (int c = 0; c < macd1.Component.Length; c++) { if (firstBar < macd1.Component[c].FirstBar) { firstBar = macd1.Component[c].FirstBar; } if (firstBar < macd2.Component[c].FirstBar) { firstBar = macd2.Component[c].FirstBar; } } firstBar += 3; var adOscillator = new double[Bars]; 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 = "Oscillator", 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 of MACD rises": indLogic = IndicatorLogic.The_indicator_rises; break; case "Oscillator of MACD falls": indLogic = IndicatorLogic.The_indicator_falls; break; case "Oscillator of MACD is higher than the zero line": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; break; case "Oscillator of MACD is lower than the zero line": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; break; case "Oscillator of MACD crosses the zero line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; break; case "Oscillator of MACD crosses the zero line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; break; case "Oscillator of MACD changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; break; case "Oscillator of MACD changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; break; } OscillatorLogic(firstBar, previous, adOscillator, 0, 0, ref Component[1], ref Component[2], indLogic); }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters var referencePeriod = (int)IndParam.NumParam[3].Value; int previous = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation // --------------------------------------------------------- var macd = new MACD(); macd.Initialize(SlotType); macd.IndParam.ListParam[1].Index = IndParam.ListParam[1].Index; macd.IndParam.ListParam[2].Index = IndParam.ListParam[2].Index; macd.IndParam.ListParam[3].Index = 0; macd.IndParam.NumParam[0].Value = IndParam.NumParam[0].Value; macd.IndParam.NumParam[1].Value = IndParam.NumParam[1].Value; macd.IndParam.NumParam[2].Value = IndParam.NumParam[2].Value; macd.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked; macd.Calculate(DataSet); double[] indicatorMa = MovingAverage(referencePeriod, previous, MAMethod.Simple, macd.Component[0].Value); double[] marketMa = MovingAverage(referencePeriod, previous, MAMethod.Simple, Close); // ---------------------------------------------------------- int firstBar = macd.Component[0].FirstBar + referencePeriod + 2; var cd = new double[Bars]; if (IndParam.ListParam[0].Text == "Convergence") for (int bar = firstBar; bar < Bars; bar++) cd[bar] = IsConvergence(indicatorMa, marketMa, bar); else if (IndParam.ListParam[0].Text == "Divergence") for (int bar = firstBar; bar < Bars; bar++) cd[bar] = IsDivergence(indicatorMa, marketMa, bar); // Saving the components Component = new IndicatorComp[4]; Component[0] = new IndicatorComp { CompName = "MACD Histogram", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Line, ChartColor = Color.RoyalBlue, FirstBar = firstBar, Value = macd.Component[0].Value }; Component[1] = new IndicatorComp { CompName = "MACD MA", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Line, ChartColor = Color.Red, FirstBar = firstBar, Value = indicatorMa }; Component[2] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = cd }; Component[3] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = cd }; // 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"; } }