Forex_Strategy_Builder.Data_Bars_Filter.Calculate C# (CSharp) Method

Calculate() public method

Calculates the indicator's components
public Calculate ( SlotTypes slotType ) : void
slotType SlotTypes
return void
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            int iNewest = (int)IndParam.NumParam[0].Value;
            int iOldest = (int)IndParam.NumParam[1].Value;

            // Calculation
            int iFirstBar = 0;
            double[] adBars = new double[Bars];

            // Calculation of the logic
            switch (IndParam.ListParam[0].Text)
            {
                case "Do not use the newest bars":
                    for (int iBar = iFirstBar; iBar < Bars - iNewest; iBar++)
                    {
                        adBars[iBar] = 1;
                    }

                    break;

                case "Do not use the oldest bars":
                    iFirstBar = Math.Min(iOldest, Bars - Configs.MIN_BARS);

                    for (int iBar = iFirstBar; iBar < Bars; iBar++)
                    {
                        adBars[iBar] = 1;
                    }

                    break;

                case "Do not use the newest bars and oldest bars":
                    iFirstBar = Math.Min(iOldest, Bars - Configs.MIN_BARS);
                    int iLastBar = Math.Max(iFirstBar + Configs.MIN_BARS, Bars - iNewest);

                    for (int iBar = iFirstBar; iBar < iLastBar; iBar++)
                    {
                        adBars[iBar] = 1;
                    }

                    break;

                case "Use the newest bars only":
                    iFirstBar = Math.Max(0, Bars - iNewest);
                    iFirstBar = Math.Min(iFirstBar, Bars - Configs.MIN_BARS);

                    for (int iBar = iFirstBar; iBar < Bars; iBar++)
                    {
                        adBars[iBar] = 1;
                    }

                    break;

                case "Use the oldest bars only":
                    iOldest = Math.Max(Configs.MIN_BARS, iOldest);

                    for (int iBar = iFirstBar; iBar < iOldest; iBar++)
                    {
                        adBars[iBar] = 1;
                    }

                    break;

                default:
                    break;
            }

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

            Component[0] = new IndicatorComp();
            Component[0].CompName      = "(No) Used bars";
            Component[0].DataType      = IndComponentType.AllowOpenLong;
            Component[0].ChartType     = IndChartType.NoChart;
            Component[0].ShowInDynInfo = false;
            Component[0].FirstBar      = iFirstBar;
            Component[0].Value         = adBars;

            Component[1] = new IndicatorComp();
            Component[1].CompName      = "(No) Used bars";
            Component[1].DataType      = IndComponentType.AllowOpenShort;
            Component[1].ChartType     = IndChartType.NoChart;
            Component[1].ShowInDynInfo = false;
            Component[1].FirstBar      = iFirstBar;
            Component[1].Value         = adBars;

            return;
        }