Forex_Strategy_Builder.Round_Number.Calculate C# (CSharp) Метод

Calculate() публичный Метод

Calculates the indicator's components
public Calculate ( SlotTypes slotType ) : void
slotType SlotTypes
Результат void
        public override void Calculate(SlotTypes slotType)
        {
            // Reading the parameters
            double dShift  = IndParam.NumParam[0].Value * Point;
            int    iDigids = (int)IndParam.NumParam[1].Value;

            // Calculation
            double[] adUpperRN = new double[Bars];
            double[] adLowerRN = new double[Bars];

            int iFirstBar = 1;

            for (int iBar = 1; iBar < Bars; iBar++)
            {
                double dNearestRound;

                int iCutDigids = Digits - iDigids;
                if (iCutDigids >= 0)
                    dNearestRound = Math.Round(Open[iBar], iCutDigids);
                else
                    dNearestRound = Math.Round(Open[iBar] * Math.Pow(10, iCutDigids)) / Math.Pow(10, iCutDigids);

                if (dNearestRound < Open[iBar])
                {
                    adUpperRN[iBar] = dNearestRound + (Point * Math.Pow(10, iDigids));
                    adLowerRN[iBar] = dNearestRound;
                }
                else
                {
                    adUpperRN[iBar] = dNearestRound;
                    adLowerRN[iBar] = dNearestRound - (Point * Math.Pow(10, iDigids));
                }
            }

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

            Component[0] = new IndicatorComp();
            Component[0].CompName   = "Higher round number";
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Level;
            Component[0].ChartColor = Color.SpringGreen;
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = adUpperRN;

            Component[1] = new IndicatorComp();
            Component[1].CompName   = "Lower round number";
            Component[1].DataType   = IndComponentType.IndicatorValue;
            Component[1].ChartType  = IndChartType.Level;
            Component[1].ChartColor = Color.DarkRed;
            Component[1].FirstBar   = iFirstBar;
            Component[1].Value      = adLowerRN;

            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];

            if (slotType == SlotTypes.Open)
            {
                Component[2].CompName = "Long position entry price";
                Component[2].DataType = IndComponentType.OpenLongPrice;
                Component[3].CompName = "Short position entry price";
                Component[3].DataType = IndComponentType.OpenShortPrice;
            }
            else if (slotType == SlotTypes.Close)
            {
                Component[2].CompName = "Long position closing price";
                Component[2].DataType = IndComponentType.CloseLongPrice;
                Component[3].CompName = "Short position closing price";
                Component[3].DataType = IndComponentType.CloseShortPrice;
            }

            switch (IndParam.ListParam[0].Text)
            {
                case "Enter long at the higher round number":
                case "Exit long at the higher round number":
                    for (int iBar = iFirstBar; iBar < Bars; iBar++)
                    {
                        Component[2].Value[iBar] = adUpperRN[iBar] + dShift;
                        Component[3].Value[iBar] = adLowerRN[iBar] - dShift;
                    }
                    break;
                case "Enter long at the lower round number":
                case "Exit long at the lower round number":
                    for (int iBar = iFirstBar; iBar < Bars; iBar++)
                    {
                        Component[2].Value[iBar] = adLowerRN[iBar] - dShift;
                        Component[3].Value[iBar] = adUpperRN[iBar] + dShift;
                    }
                    break;
                default:
                    break;
            }

            return;
        }