Forex_Strategy_Builder.Gator_Oscillator.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)
        {
            MAMethod  maMethod  = (MAMethod )IndParam.ListParam[1].Index;
            BasePrice basePrice = (BasePrice)IndParam.ListParam[2].Index;
            int iNJaws  = (int)IndParam.NumParam[0].Value;
            int iSJaws  = (int)IndParam.NumParam[1].Value;
            int iNTeeth = (int)IndParam.NumParam[2].Value;
            int iSTeeth = (int)IndParam.NumParam[3].Value;
            int iNLips  = (int)IndParam.NumParam[4].Value;
            int iSLips  = (int)IndParam.NumParam[5].Value;
            int iPrvs   = IndParam.CheckParam[0].Checked ? 1 : 0;

            int iFirstBar = Math.Max(iNJaws + iSJaws + 2, iNTeeth + iSTeeth + 2);
            iFirstBar = Math.Max(iFirstBar, iNLips + iSLips + 2);

            // Calculation
            double[] adJaws  = MovingAverage(iNJaws , iSJaws , maMethod, Price(basePrice));
            double[] adTeeth = MovingAverage(iNTeeth, iSTeeth, maMethod, Price(basePrice));
            double[] adLips  = MovingAverage(iNLips , iSLips , maMethod, Price(basePrice));

            double[] adUpperGator = new double[Bars];
            double[] adLowerGator = new double[Bars];

            for (int iBar = 0; iBar < Bars; iBar++)
            {
                adUpperGator[iBar] =  Math.Abs(adJaws[iBar]  - adTeeth[iBar]);
                adLowerGator[iBar] = -Math.Abs(adTeeth[iBar] - adLips[iBar]);
            }

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

            Component[0] = new IndicatorComp();
            Component[0].CompName  = "Upper Gator";
            Component[0].DataType  = IndComponentType.IndicatorValue;
            Component[0].ChartType = IndChartType.Histogram;
            Component[0].FirstBar  = iFirstBar;
            Component[0].Value     = adUpperGator;

            Component[1] = new IndicatorComp();
            Component[1].CompName  = "Lower Gator";
            Component[1].DataType  = IndComponentType.IndicatorValue;
            Component[1].ChartType = IndChartType.Histogram;
            Component[1].FirstBar  = iFirstBar;
            Component[1].Value     = adLowerGator;

            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 Gator Oscillator expands":
                    for (int iBar = iFirstBar; iBar < Bars; iBar++)
                    {
                        Component[2].Value[iBar] = (adUpperGator[iBar - iPrvs] - adLowerGator[iBar - iPrvs]) > (adUpperGator[iBar - iPrvs - 1] - adLowerGator[iBar - iPrvs - 1]) + Sigma() ? 1 : 0;
                        Component[3].Value[iBar] = (adUpperGator[iBar - iPrvs] - adLowerGator[iBar - iPrvs]) > (adUpperGator[iBar - iPrvs - 1] - adLowerGator[iBar - iPrvs - 1]) + Sigma() ? 1 : 0;
                    }
                    break;

                case "The Gator Oscillator contracts":
                    for (int iBar = iFirstBar; iBar < Bars; iBar++)
                    {
                        Component[2].Value[iBar] = (adUpperGator[iBar - iPrvs] - adLowerGator[iBar - iPrvs]) < (adUpperGator[iBar - iPrvs - 1] - adLowerGator[iBar - iPrvs - 1]) - Sigma() ? 1 : 0;
                        Component[3].Value[iBar] = (adUpperGator[iBar - iPrvs] - adLowerGator[iBar - iPrvs]) < (adUpperGator[iBar - iPrvs - 1] - adLowerGator[iBar - iPrvs - 1]) - Sigma() ? 1 : 0;
                    }
                    break;

                default:
                    break;
            }

            return;
        }