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

            // Reading the parameters
            var maSignalMAMethod = (MAMethod) IndParam.ListParam[2].Index;
            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 roc1 = new RateOfChange();
            roc1.Initialize(SlotType);
            roc1.IndParam.ListParam[1].Index = IndParam.ListParam[1].Index;
            roc1.IndParam.ListParam[2].Index = IndParam.ListParam[3].Index;
            roc1.IndParam.NumParam[0].Value = IndParam.NumParam[0].Value;
            roc1.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked;
            roc1.Calculate(DataSet);

            double[] adIndicator1 = roc1.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 = "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 "ROC MA Oscillator rises":
                    indLogic = IndicatorLogic.The_indicator_rises;
                    break;

                case "ROC MA Oscillator falls":
                    indLogic = IndicatorLogic.The_indicator_falls;
                    break;

                case "ROC MA Oscillator is higher than the zero line":
                    indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line;
                    break;

                case "ROC MA Oscillator is lower than the zero line":
                    indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line;
                    break;

                case "ROC MA Oscillator crosses the zero line upward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward;
                    break;

                case "ROC MA Oscillator crosses the zero line downward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward;
                    break;

                case "ROC MA Oscillator changes its direction upward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward;
                    break;

                case "ROC MA 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);
        }
예제 #2
0
        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 roc1 = new RateOfChange();

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

            var roc2 = new RateOfChange();

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

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