public override void Calculate(IDataSet dataSet)
        {
            DataSet = dataSet;

            // Reading the parameters
            var referencePeriod = (int) IndParam.NumParam[1].Value;
            int previous = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation

            // ---------------------------------------------------------
            var rsi = new RSI();
            rsi.Initialize(SlotType);
            rsi.IndParam.ListParam[1].Index = IndParam.ListParam[1].Index;
            rsi.IndParam.ListParam[2].Index = IndParam.ListParam[2].Index;
            rsi.IndParam.NumParam[0].Value = IndParam.NumParam[0].Value;
            rsi.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked;
            rsi.Calculate(DataSet);

            double[] indicatorMa = MovingAverage(referencePeriod, previous, MAMethod.Simple, rsi.Component[0].Value);
            double[] marketMa = MovingAverage(referencePeriod, previous, MAMethod.Simple, Close);
            // ----------------------------------------------------------

            int firstBar = rsi.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 = "RSI",
                DataType = IndComponentType.IndicatorValue,
                ChartType = IndChartType.Line,
                ChartColor = Color.Blue,
                FirstBar = firstBar,
                Value = rsi.Component[0].Value
            };

            Component[1] = new IndicatorComp
            {
                CompName = "RSI 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";
            }
        }
        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 rsi1 = new RSI();
            rsi1.Initialize(SlotType);
            rsi1.IndParam.ListParam[1].Index = IndParam.ListParam[1].Index;
            rsi1.IndParam.ListParam[2].Index = IndParam.ListParam[2].Index;
            rsi1.IndParam.NumParam[0].Value = IndParam.NumParam[0].Value;
            rsi1.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked;
            rsi1.Calculate(DataSet);

            var rsi2 = new RSI();
            rsi2.Initialize(SlotType);
            rsi2.IndParam.ListParam[1].Index = IndParam.ListParam[1].Index;
            rsi2.IndParam.ListParam[2].Index = IndParam.ListParam[2].Index;
            rsi2.IndParam.NumParam[0].Value = IndParam.NumParam[1].Value;
            rsi2.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked;
            rsi2.Calculate(DataSet);

            double[] adIndicator1 = rsi1.Component[0].Value;
            double[] adIndicator2 = rsi2.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 = "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 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);
        }