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

            // Calculation
            int firstBar = period1 + period2 + 2;
            var oscillator = new double[Bars];

            // ---------------------------------------------------------
            var atr = new AverageTrueRange();
            atr.Initialize(SlotType);
            atr.IndParam.ListParam[1].Index = IndParam.ListParam[1].Index;
            atr.IndParam.NumParam[0].Value = IndParam.NumParam[0].Value;
            atr.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked;
            atr.Calculate(dataSet);

            double[] indicator1 = atr.Component[0].Value;
            double[] indicator2 = MovingAverage(period2, 0, maSignalMaMethod, 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 indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
                case "ATR MA Oscillator rises":
                    indLogic = IndicatorLogic.The_indicator_rises;
                    break;

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

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

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

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

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

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

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

            NoDirectionOscillatorLogic(firstBar, previous, oscillator, 0, ref Component[1], indLogic);
            Component[2].Value = Component[1].Value;
        }
        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 previous         = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int firstBar   = period1 + period2 + 2;
            var oscillator = new double[Bars];

// ---------------------------------------------------------
            var atr = new AverageTrueRange();

            atr.Initialize(SlotType);
            atr.IndParam.ListParam[1].Index    = IndParam.ListParam[1].Index;
            atr.IndParam.NumParam[0].Value     = IndParam.NumParam[0].Value;
            atr.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked;
            atr.Calculate(dataSet);

            double[] indicator1 = atr.Component[0].Value;
            double[] indicator2 = MovingAverage(period2, 0, maSignalMaMethod, 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 indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
            case "ATR MA Oscillator rises":
                indLogic = IndicatorLogic.The_indicator_rises;
                break;

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

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

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

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

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

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

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

            NoDirectionOscillatorLogic(firstBar, previous, oscillator, 0, ref Component[1], indLogic);
            Component[2].Value = Component[1].Value;
        }
Exemplo n.º 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 atr1 = new AverageTrueRange();

            atr1.Initialize(SlotType);

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

            var atr2 = new AverageTrueRange();

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

            double[] adIndicator1 = atr1.Component[0].Value;
            double[] adIndicator2 = atr2.Component[0].Value;
// ----------------------------------------------------------

            int firstBar = 0;

            for (int c = 0; c < atr1.Component.Length; c++)
            {
                if (firstBar < atr1.Component[c].FirstBar)
                {
                    firstBar = atr1.Component[c].FirstBar;
                }
                if (firstBar < atr2.Component[c].FirstBar)
                {
                    firstBar = atr2.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;
            }

            NoDirectionOscillatorLogic(firstBar, prvs, adOscillator, 0, ref Component[1], indLogic);
            Component[2].Value = Component[1].Value;
        }
Exemplo n.º 4
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 atr1 = new AverageTrueRange();
            atr1.Initialize(SlotType);

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

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

            double[] adIndicator1 = atr1.Component[0].Value;
            double[] adIndicator2 = atr2.Component[0].Value;
            // ----------------------------------------------------------

            int firstBar = 0;
            for (int c = 0; c < atr1.Component.Length; c++)
            {
                if (firstBar < atr1.Component[c].FirstBar)
                    firstBar = atr1.Component[c].FirstBar;
                if (firstBar < atr2.Component[c].FirstBar)
                    firstBar = atr2.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;
            }

            NoDirectionOscillatorLogic(firstBar, prvs, adOscillator, 0, ref Component[1], indLogic);
            Component[2].Value = Component[1].Value;
        }