Forex_Strategy_Builder.Moving_Averages_Crossover.Calculate C# (CSharp) Méthode

Calculate() public méthode

Calculates the indicator's components
public Calculate ( SlotTypes slotType ) : void
slotType SlotTypes
Résultat void
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            BasePrice basePrice    = (BasePrice)IndParam.ListParam[1].Index;
            MAMethod  fastMAMethod = (MAMethod )IndParam.ListParam[3].Index;
            MAMethod  slowMAMethod = (MAMethod )IndParam.ListParam[4].Index;
            int       iNFastMA  = (int)IndParam.NumParam[0].Value;
            int       iNSlowMA  = (int)IndParam.NumParam[1].Value;
            int       iSFastMA  = (int)IndParam.NumParam[2].Value;
            int       iSSlowMA  = (int)IndParam.NumParam[3].Value;
            int       iPrvs     = IndParam.CheckParam[0].Checked ? 1 : 0;

            int     iFirstBar = (int)Math.Max(iNFastMA + iSFastMA, iNSlowMA + iSSlowMA) + 2;
            double[] adMAFast = MovingAverage(iNFastMA, iSFastMA, fastMAMethod, Price(basePrice));
            double[] adMASlow = MovingAverage(iNSlowMA, iSSlowMA, slowMAMethod, Price(basePrice));
            double[] adMAOscillator = new double[Bars];

            for (int iBar = iFirstBar; iBar < Bars; iBar++)
                adMAOscillator[iBar] = adMAFast[iBar] - adMASlow[iBar];

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

            Component[0] = new IndicatorComp();
            Component[0].CompName   = "Fast Moving Average";
            Component[0].ChartColor = Color.Goldenrod;
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Line;
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = adMAFast;

            Component[1] = new IndicatorComp();
            Component[1].CompName   = "Slow Moving Average";
            Component[1].ChartColor = Color.IndianRed;
            Component[1].DataType   = IndComponentType.IndicatorValue;
            Component[1].ChartType  = IndChartType.Line;
            Component[1].FirstBar   = iFirstBar;
            Component[1].Value      = adMASlow;

            Component[2] = new IndicatorComp();
            Component[2].ChartType = IndChartType.NoChart;
            Component[2].FirstBar  = iFirstBar;
            Component[2].Value     = new double[Bars];

            Component[3] = new IndicatorComp();
            Component[3].ChartType = IndChartType.NoChart;
            Component[3].FirstBar  = iFirstBar;
            Component[3].Value     = new double[Bars];

            // 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";
            }

            // Calculation of the logic
            IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter;

            switch (IndParam.ListParam[0].Text)
            {
                case "The Fast MA crosses the Slow MA upward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward;
                    break;
                case "The Fast MA crosses the Slow MA downward":
                    indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward;
                    break;
                case "The Fast MA is higher than the Slow MA":
                    indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line;
                    break;
                case "The Fast MA is lower than the Slow MA":
                    indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line;
                    break;
                default:
                    break;
            }

            OscillatorLogic(iFirstBar, iPrvs, adMAOscillator, 0, 0, ref Component[2], ref Component[3], indLogic);

            return;
        }