Forex_Strategy_Builder.Indicator.BandIndicatorLogic C# (CSharp) Метод

BandIndicatorLogic() защищенный Метод

Calculates the logic of a band indicator.
protected BandIndicatorLogic ( int firstBar, int prvs, double adUpperBand, double adLowerBand, IndicatorComp &indCompLong, IndicatorComp &indCompShort, BandIndLogic indLogic ) : bool
firstBar int The first bar number.
prvs int To use the previous bar or not.
adUpperBand double The Upper band values.
adLowerBand double The Lower band values.
indCompLong IndicatorComp Indicator component for Long position.
indCompShort IndicatorComp Indicator component for Short position.
indLogic BandIndLogic The chosen logic.
Результат bool
        protected bool BandIndicatorLogic(int firstBar, int prvs, double[] adUpperBand, double[] adLowerBand, ref IndicatorComp indCompLong, ref IndicatorComp indCompShort, BandIndLogic indLogic)
        {
            double sigma = Sigma();

            switch (indLogic)
            {
                case BandIndLogic.The_bar_opens_below_the_Upper_Band:
                    for (int bar = firstBar; bar < Bars; bar++)
                    {
                        indCompLong.Value[bar]  = Open[bar] < adUpperBand[bar - prvs] - sigma ? 1 : 0;
                        indCompShort.Value[bar] = Open[bar] > adLowerBand[bar - prvs] + sigma ? 1 : 0;
                    }
                    break;

                case BandIndLogic.The_bar_opens_above_the_Upper_Band:
                    for (int bar = firstBar; bar < Bars; bar++)
                    {
                        indCompLong.Value[bar]  = Open[bar] > adUpperBand[bar - prvs] + sigma ? 1 : 0;
                        indCompShort.Value[bar] = Open[bar] < adLowerBand[bar - prvs] - sigma ? 1 : 0;
                    }
                    break;

                case BandIndLogic.The_bar_opens_below_the_Lower_Band:
                    for (int bar = firstBar; bar < Bars; bar++)
                    {
                        indCompLong.Value[bar]  = Open[bar] < adLowerBand[bar - prvs] - sigma ? 1 : 0;
                        indCompShort.Value[bar] = Open[bar] > adUpperBand[bar - prvs] + sigma ? 1 : 0;
                    }
                    break;

                case BandIndLogic.The_bar_opens_above_the_Lower_Band:
                    for (int bar = firstBar; bar < Bars; bar++)
                    {
                        indCompLong.Value[bar]  = Open[bar] > adLowerBand[bar - prvs] + sigma ? 1 : 0;
                        indCompShort.Value[bar] = Open[bar] < adUpperBand[bar - prvs] - sigma ? 1 : 0;
                    }
                    break;

                case BandIndLogic.The_bar_opens_below_the_Upper_Band_after_opening_above_it:
                    for (int bar = firstBar; bar < Bars; bar++)
                    {
                        int baseBar = bar - 1;
                        while (Math.Abs(Open[baseBar] - adUpperBand[baseBar - prvs]) < sigma && baseBar > firstBar)
                        { baseBar--; }

                        indCompLong.Value[bar]  = Open[bar] < adUpperBand[bar - prvs] - sigma && Open[baseBar] > adUpperBand[baseBar - prvs] + sigma ? 1 : 0;

                        baseBar = bar - 1;
                        while (Math.Abs(Open[baseBar] - adLowerBand[baseBar - prvs]) < sigma && baseBar > firstBar)
                        { baseBar--; }

                        indCompShort.Value[bar] = Open[bar] > adLowerBand[bar - prvs] + sigma && Open[baseBar] < adLowerBand[baseBar - prvs] - sigma ? 1 : 0;
                    }
                    break;

                case BandIndLogic.The_bar_opens_above_the_Upper_Band_after_opening_below_it:
                    for (int bar = firstBar; bar < Bars; bar++)
                    {
                        int baseBar = bar - 1;
                        while (Math.Abs(Open[baseBar] - adUpperBand[baseBar - prvs]) < sigma && baseBar > firstBar)
                        { baseBar--; }

                        indCompLong.Value[bar]  = Open[bar] > adUpperBand[bar - prvs] + sigma && Open[baseBar] < adUpperBand[baseBar - prvs] - sigma ? 1 : 0;

                        baseBar = bar - 1;
                        while (Math.Abs(Open[baseBar] - adLowerBand[baseBar - prvs]) < sigma && baseBar > firstBar)
                        { baseBar--; }

                        indCompShort.Value[bar] = Open[bar] < adLowerBand[bar - prvs] - sigma && Open[baseBar] > adLowerBand[baseBar - prvs] + sigma ? 1 : 0;
                    }
                    break;

                case BandIndLogic.The_bar_opens_below_the_Lower_Band_after_opening_above_it:
                    for (int bar = firstBar; bar < Bars; bar++)
                    {
                        int baseBar = bar - 1;
                        while (Math.Abs(Open[baseBar] - adLowerBand[baseBar - prvs]) < sigma && baseBar > firstBar)
                        { baseBar--; }

                        indCompLong.Value[bar]  = Open[bar] < adLowerBand[bar - prvs] - sigma && Open[baseBar] > adLowerBand[baseBar - prvs] + sigma ? 1 : 0;

                        baseBar = bar - 1;
                        while (Math.Abs(Open[baseBar] - adUpperBand[baseBar - prvs]) < sigma && baseBar > firstBar)
                        { baseBar--; }

                        indCompShort.Value[bar] = Open[bar] > adUpperBand[bar - prvs] + sigma && Open[baseBar] < adUpperBand[baseBar - prvs] - sigma ? 1 : 0;
                    }
                    break;

                case BandIndLogic.The_bar_opens_above_the_Lower_Band_after_opening_below_it:
                    for (int bar = firstBar; bar < Bars; bar++)
                    {
                        int baseBar = bar - 1;
                        while (Math.Abs(Open[baseBar] - adLowerBand[baseBar - prvs]) < sigma && baseBar > firstBar)
                        { baseBar--; }

                        indCompLong.Value[bar]  = Open[bar] > adLowerBand[bar - prvs] + sigma && Open[baseBar] < adLowerBand[baseBar - prvs] - sigma ? 1 : 0;

                        baseBar = bar - 1;
                        while (Math.Abs(Open[baseBar] - adUpperBand[baseBar - prvs]) < sigma && baseBar > firstBar)
                        { baseBar--; }

                        indCompShort.Value[bar] = Open[bar] < adUpperBand[bar - prvs] - sigma && Open[baseBar] > adUpperBand[baseBar - prvs] + sigma ? 1 : 0;
                    }
                    break;

                case BandIndLogic.The_bar_closes_below_the_Upper_Band:
                    for (int bar = firstBar; bar < Bars; bar++)
                    {
                        indCompLong.Value[bar]  = Close[bar] < adUpperBand[bar - prvs] - sigma ? 1 : 0;
                        indCompShort.Value[bar] = Close[bar] > adLowerBand[bar - prvs] + sigma ? 1 : 0;
                    }
                    break;

                case BandIndLogic.The_bar_closes_above_the_Upper_Band:
                    for (int bar = firstBar; bar < Bars; bar++)
                    {
                        indCompLong.Value[bar]  = Close[bar] > adUpperBand[bar - prvs] + sigma ? 1 : 0;
                        indCompShort.Value[bar] = Close[bar] < adLowerBand[bar - prvs] - sigma ? 1 : 0;
                    }
                    break;

                case BandIndLogic.The_bar_closes_below_the_Lower_Band:
                    for (int bar = firstBar; bar < Bars; bar++)
                    {
                        indCompLong.Value[bar]  = Close[bar] < adLowerBand[bar - prvs] - sigma ? 1 : 0;
                        indCompShort.Value[bar] = Close[bar] > adUpperBand[bar - prvs] + sigma ? 1 : 0;
                    }
                    break;

                case BandIndLogic.The_bar_closes_above_the_Lower_Band:
                    for (int bar = firstBar; bar < Bars; bar++)
                    {
                        indCompLong.Value[bar]  = Close[bar] > adLowerBand[bar - prvs] + sigma ? 1 : 0;
                        indCompShort.Value[bar] = Close[bar] < adUpperBand[bar - prvs] - sigma ? 1 : 0;
                    }
                    break;

                default:
                    return false;
            }

            return true;
        }