Forex_Strategy_Builder.ATR_Stop.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
            MAMethod maMethod = (MAMethod)IndParam.ListParam[1].Index;
            int period = (int)IndParam.NumParam[0].Value;
            int multipl = (int)IndParam.NumParam[1].Value;
            int prev = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int firstBar = period + 2;

            double[] ATR = new double[Bars];

            for (int bar = 1; bar < Bars; bar++)
                ATR[bar] = Math.Max(High[bar], Close[bar - 1]) - Math.Min(Low[bar], Close[bar - 1]);

            ATR = MovingAverage(period, 0, maMethod, ATR);

            double[] ATRStop = new double[Bars];
            double minStop = 5 * Point;

            for (int bar = firstBar; bar < Bars - prev; bar++)
                ATRStop[bar + prev] = Math.Max(ATR[bar] * multipl, minStop);

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

            Component[0] = new IndicatorComp();
            Component[0].CompName      = "ATR Stop margin";
            Component[0].DataType      = IndComponentType.IndicatorValue;
            Component[0].FirstBar      = firstBar;
            Component[0].ShowInDynInfo = false;
            Component[0].Value         = ATRStop;

            Component[1]               = new IndicatorComp();
            Component[1].CompName      = "ATR Stop for the transferred position";
            Component[1].DataType	   = IndComponentType.Other;
            Component[1].ShowInDynInfo = false;
            Component[1].FirstBar	   = firstBar;
            Component[1].Value	       = new double[Bars];

            return;
        }