Forex_Strategy_Builder.Narrow_Range.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)
        {
            int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int iStepBack = (IndParam.ListParam[0].Text == "There is a NR4 formation" ? 3 : 6);
            int iFirstBar = iStepBack + iPrvs;
            double[] adNR    = new double[Bars];
            double[] adRange = new double[Bars];

            for (int iBar = 0; iBar < Bars; iBar++)
            {
                adRange[iBar] = High[iBar] - Low[iBar];
                adNR[iBar] = 0;
            }

            // Calculation of the logic
            for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                bool bNarrowRange = true;
                for (int i = 1; i <= iStepBack; i++)
                    if (adRange[iBar - i - iPrvs] <= adRange[iBar - iPrvs])
                    {
                        bNarrowRange = false;
                        break;
                    }

                if (bNarrowRange) adNR[iBar] = 1;
            }

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

            Component[0] = new IndicatorComp();
            Component[0].CompName  = "Bar Range";
            Component[0].DataType  = IndComponentType.IndicatorValue;
            Component[0].ChartType = IndChartType.Histogram;
            Component[0].FirstBar  = iFirstBar;
            Component[0].Value     = new double[Bars];
            for (int i = 0; i < Bars; i++)
                Component[0].Value[i] = (double)Math.Round(adRange[i] / Point);

            Component[1] = new IndicatorComp();
            Component[1].CompName  = "Allow long entry";
            Component[1].DataType  = IndComponentType.AllowOpenLong;
            Component[1].ChartType = IndChartType.NoChart;
            Component[1].FirstBar  = iFirstBar;
            Component[1].Value     = adNR;

            Component[2] = new IndicatorComp();
            Component[2].CompName  = "Allow short entry";
            Component[2].DataType  = IndComponentType.AllowOpenShort;
            Component[2].ChartType = IndChartType.NoChart;
            Component[2].FirstBar  = iFirstBar;
            Component[2].Value     = adNR;

            return;
        }