Forex_Strategy_Builder.Relative_Vigor_Index.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
            int nRVI  = (int)IndParam.NumParam[0].Value;
            int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation
            int iFirstBar = nRVI + 4;

            double[] adRVI = new double[Bars];
            for (int iBar = nRVI + 3; iBar < Bars; iBar++)
            {
                double dNum   = 0;
                double dDeNum = 0;
                for (int j = iBar; j > iBar - nRVI; j--)
                {
                    double dValueUp   = ((Close[j] - Open[j]) + 2 * (Close[j - 1] - Open[j - 1]) + 2 * (Close[j - 2] - Open[j - 2]) + (Close[j - 3] - Open[j - 3])) / 6;
                    double dValueDown = ((High[j]  -  Low[j]) + 2 * (High[j - 1]  -  Low[j - 1]) + 2 * (High[j - 2]  -  Low[j - 2]) + (High[j - 3]  -  Low[j - 3])) / 6;
                    dNum   += dValueUp;
                    dDeNum += dValueDown;
                }
                if (dDeNum != 0)
                    adRVI[iBar] = dNum / dDeNum;
                else
                    adRVI[iBar] = dNum;
            }

            double[] adMASignal = new double[Bars];
            for (int iBar = 4; iBar < Bars; iBar++)
                adMASignal[iBar] = (adRVI[iBar] + 2 * adRVI[iBar - 1] + 2 * adRVI[iBar - 2] + adRVI[iBar - 3]) / 6;

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

            Component[0] = new IndicatorComp();
            Component[0].CompName   = "RVI Line";
            Component[0].DataType   = IndComponentType.IndicatorValue;
            Component[0].ChartType  = IndChartType.Line;
            Component[0].ChartColor = Color.Green;
            Component[0].FirstBar   = iFirstBar;
            Component[0].Value      = adRVI;

            Component[1] = new IndicatorComp();
            Component[1].CompName   = "Signal line";
            Component[1].DataType   = IndComponentType.IndicatorValue;
            Component[1].ChartType  = IndChartType.Line;
            Component[1].ChartColor = Color.Red;
            Component[1].FirstBar   = iFirstBar;
            Component[1].Value      = adMASignal;

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

            switch (IndParam.ListParam[0].Text)
            {
                case "The RVI line rises":
                    OscillatorLogic(iFirstBar, iPrvs, adRVI, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_rises);
                    break;

                case "The RVI line falls":
                    OscillatorLogic(iFirstBar, iPrvs, adRVI, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_falls);
                    break;

                case "The RVI line is higher than zero":
                    OscillatorLogic(iFirstBar, iPrvs, adRVI, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_is_higher_than_the_level_line);
                    break;

                case "The RVI line is lower than zero":
                    OscillatorLogic(iFirstBar, iPrvs, adRVI, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_is_lower_than_the_level_line);
                    break;

                case "The RVI line crosses the zero line upward":
                    OscillatorLogic(iFirstBar, iPrvs, adRVI, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_crosses_the_level_line_upward);
                    break;

                case "The RVI line crosses the zero line downward":
                    OscillatorLogic(iFirstBar, iPrvs, adRVI, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_crosses_the_level_line_downward);
                    break;

                case "The RVI line changes its direction upward":
                    OscillatorLogic(iFirstBar, iPrvs, adRVI, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_changes_its_direction_upward);
                    break;

                case "The RVI line changes its direction downward":
                    OscillatorLogic(iFirstBar, iPrvs, adRVI, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_changes_its_direction_downward);
                    break;

                case "The RVI line crosses the Signal line upward":
                    IndicatorCrossesAnotherIndicatorUpwardLogic(iFirstBar, iPrvs, adRVI, adMASignal, ref Component[2], ref Component[3]);
                    break;

                case "The RVI line crosses the Signal line downward":
                    IndicatorCrossesAnotherIndicatorDownwardLogic(iFirstBar, iPrvs, adRVI, adMASignal, ref Component[2], ref Component[3]);
                    break;

                case "The RVI line is higher than the Signal line":
                    IndicatorIsHigherThanAnotherIndicatorLogic(iFirstBar, iPrvs, adRVI, adMASignal, ref Component[2], ref Component[3]);
                    break;

                case "The RVI line is lower than the Signal line":
                    IndicatorIsLowerThanAnotherIndicatorLogic(iFirstBar, iPrvs, adRVI, adMASignal, ref Component[2], ref Component[3]);
                    break;

                default:
                    break;
            }

            return;
        }