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

            // Reading the parameters
            var maSignalMAMethod = (MAMethod) IndParam.ListParam[2].Index;
            var iPeriod1 = (int) IndParam.NumParam[0].Value;
            var iPeriod2 = (int) IndParam.NumParam[1].Value;
            int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int iFirstBar = iPeriod1 + iPeriod2 + 2;
            var adOscillator = new double[Bars];

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

            double[] adIndicator1 = cci.Component[0].Value;
            double[] adIndicator2 = MovingAverage(iPeriod2, 0, maSignalMAMethod, adIndicator1);
            // ----------------------------------------------------------

            for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                adOscillator[iBar] = adIndicator1[iBar] - adIndicator2[iBar];
            }

            // Saving the components
            Component = new IndicatorComp[3];

            Component[0] = new IndicatorComp
                {
                    CompName = "Histogram",
                    DataType = IndComponentType.IndicatorValue,
                    ChartType = IndChartType.Histogram,
                    FirstBar = iFirstBar,
                    Value = adOscillator
                };

            Component[1] = new IndicatorComp
                {
                    ChartType = IndChartType.NoChart,
                    FirstBar = iFirstBar,
                    Value = new double[Bars]
                };

            Component[2] = new IndicatorComp
                {
                    ChartType = IndChartType.NoChart,
                    FirstBar = iFirstBar,
                    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 "CCI MA Oscillator rises":
                    indLogic = IndicatorLogic.The_indicator_rises;
                    break;

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

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

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

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

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

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

                case "CCI MA Oscillator changes its direction downward":
                    indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward;
                    break;
            }

            OscillatorLogic(iFirstBar, iPrvs, 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[2].Value;
            int previous = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation

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

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

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

            Component[1] = new IndicatorComp
            {
                CompName = "CCI 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";
            }
        }
Exemple #3
0
        public override void Calculate(IDataSet dataSet)
        {
            DataSet = dataSet;

            // Reading the parameters
            int prvs = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            var adOscillator = new double[Bars];

// ---------------------------------------------------------
            var cci1 = new CommodityChannelIndex();

            cci1.Initialize(SlotType);

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

            var cci2 = new CommodityChannelIndex();

            cci2.Initialize(SlotType);

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

            double[] adIndicator1 = cci1.Component[0].Value;
            double[] adIndicator2 = cci2.Component[0].Value;
// ----------------------------------------------------------

            int firstBar = 0;

            for (int c = 0; c < cci1.Component.Length; c++)
            {
                if (firstBar < cci1.Component[c].FirstBar)
                {
                    firstBar = cci1.Component[c].FirstBar;
                }
                if (firstBar < cci2.Component[c].FirstBar)
                {
                    firstBar = cci2.Component[c].FirstBar;
                }
            }
            firstBar += 3;

            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 prvs = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            var adOscillator = new double[Bars];

            // ---------------------------------------------------------
            var cci1 = new CommodityChannelIndex();
            cci1.Initialize(SlotType);

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

            var cci2 = new CommodityChannelIndex();
            cci2.Initialize(SlotType);

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

            double[] adIndicator1 = cci1.Component[0].Value;
            double[] adIndicator2 = cci2.Component[0].Value;
            // ----------------------------------------------------------

            int firstBar = 0;
            for (int c = 0; c < cci1.Component.Length; c++)
            {
                if (firstBar < cci1.Component[c].FirstBar)
                    firstBar = cci1.Component[c].FirstBar;
                if (firstBar < cci2.Component[c].FirstBar)
                    firstBar = cci2.Component[c].FirstBar;
            }
            firstBar += 3;

            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);
        }
Exemple #5
0
        public override void Calculate(IDataSet dataSet)
        {
            DataSet = dataSet;

            // Reading the parameters
            var signalMaMethod = (MAMethod)IndParam.ListParam[2].Index;
            var period1        = (int)IndParam.NumParam[0].Value;
            var period2        = (int)IndParam.NumParam[1].Value;
            int previous       = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int firstBar   = Math.Max(period1, period2) + previous + 2;
            var oscillator = new double[Bars];

            // ---------------------------------------------------------
            var cci = new CommodityChannelIndex();

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

            double[] indicator1 = cci.Component[0].Value;
            double[] indicator2 = MovingAverage(period2, 0, signalMaMethod, indicator1);
            // ----------------------------------------------------------

            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 "CCI MA Oscillator rises":
                logicRule = IndicatorLogic.The_indicator_rises;
                break;

            case "CCI MA Oscillator falls":
                logicRule = IndicatorLogic.The_indicator_falls;
                break;

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

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

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

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

            case "CCI MA Oscillator changes its direction upward":
                logicRule = IndicatorLogic.The_indicator_changes_its_direction_upward;
                break;

            case "CCI MA 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);
        }