Forex_Strategy_Builder.Previous_Bar_Opening.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)
        {
            // Calculation
            double[] adPrevBarOpening = new double[Bars];

            int iFirstBar = 1;

            for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                adPrevBarOpening[iBar] = Open[iBar - 1];
            }

            // Saving the components
            if (slotType == SlotTypes.Open || slotType == SlotTypes.Close)
            {
                Component = new IndicatorComp[1];
            }
            else
            {
                Component = new IndicatorComp[3];

                Component[1] = new IndicatorComp();
                Component[1].ChartType = IndChartType.NoChart;
                Component[1].FirstBar  = iFirstBar;
                Component[1].Value     = new double[Bars];

                Component[2] = new IndicatorComp();
                Component[2].ChartType = IndChartType.NoChart;
                Component[2].FirstBar  = iFirstBar;
                Component[2].Value     = new double[Bars];
            }

            Component[0] = new IndicatorComp();
            Component[0].DataType  = IndComponentType.IndicatorValue;
            Component[0].CompName  = "Previous Bar Opening";
            Component[0].ChartType = IndChartType.NoChart;
            Component[0].FirstBar  = iFirstBar;
            Component[0].Value     = adPrevBarOpening;

            // Sets the Component's type
            if (slotType == SlotTypes.Open)
            {
                Component[0].DataType = IndComponentType.OpenPrice;
            }
            else if (slotType == SlotTypes.OpenFilter)
            {
                Component[1].DataType = IndComponentType.AllowOpenLong;
                Component[1].CompName = "Is long entry allowed";
                Component[2].DataType = IndComponentType.AllowOpenShort;
                Component[2].CompName = "Is short entry allowed";
            }
            else if (slotType == SlotTypes.Close)
            {
                Component[0].DataType = IndComponentType.ClosePrice;
            }
            else if (slotType == SlotTypes.CloseFilter)
            {
                Component[1].DataType = IndComponentType.ForceCloseLong;
                Component[1].CompName = "Close out long position";
                Component[2].DataType = IndComponentType.ForceCloseShort;
                Component[2].CompName = "Close out short position";
            }

            if (slotType == SlotTypes.OpenFilter || slotType == SlotTypes.CloseFilter)
            {
                switch (IndParam.ListParam[0].Text)
                {
                    case "The bar opens below the previous Bar Opening":
                        BarOpensBelowIndicatorLogic(iFirstBar, 0, adPrevBarOpening, ref Component[1], ref Component[2]);
                        break;

                    case "The bar opens above the previous Bar Opening":
                        BarOpensAboveIndicatorLogic(iFirstBar, 0, adPrevBarOpening, ref Component[1], ref Component[2]);
                        break;

                    case "The position opens above the previous Bar Opening":
                        Component[0].PosPriceDependence = PositionPriceDependence.BuyHigherSellLower;
                        Component[1].DataType = IndComponentType.Other;
                        Component[2].DataType = IndComponentType.Other;
                        Component[1].ShowInDynInfo = false;
                        Component[2].ShowInDynInfo = false;
                        break;

                    case "The position opens below the previous Bar Opening":
                        Component[0].PosPriceDependence = PositionPriceDependence.BuyLowerSelHigher;
                        Component[1].DataType = IndComponentType.Other;
                        Component[2].DataType = IndComponentType.Other;
                        Component[1].ShowInDynInfo = false;
                        Component[2].ShowInDynInfo = false;
                        break;

                    case "The bar closes below the previous Bar Opening":
                        BarClosesBelowIndicatorLogic(iFirstBar, 0, adPrevBarOpening, ref Component[1], ref Component[2]);
                        break;

                    case "The bar closes above the previous Bar Opening":
                        BarClosesAboveIndicatorLogic(iFirstBar, 0, adPrevBarOpening, ref Component[1], ref Component[2]);
                        break;

                    default:
                        break;
                }
            }

            return;
        }