Topic: Bollinger Band Upgrade

iam trying to use all the three lines of bollingerbands  to be used in the 4 slots

but i faced the problem in the code part of SlotType == SlotTypes.Open || SlotType == SlotTypes.Close

it uses the upper and lower bands as interchange to each other

My problem: I cannot add the middle line to that part of code

Any help !!!

  if (SlotType == SlotTypes.Open || SlotType == SlotTypes.Close)
            {
                if (nMA > 1)
                {
                    for (int bar = firstBar; bar < Bars; bar++)
                    {
                        // Covers the cases when the price can pass through the band without a signal.
                        double open = Open[bar]; // Current open price

                        // Upper band
                        double valueUp = adUpBand[bar - prvs]; // Current value
                        double valueUp1 = adUpBand[bar - prvs - 1]; // Previous value
                        double tempValUp = valueUp;

                        if ((valueUp1 > High[bar - 1] && valueUp < open) || // The Open price jumps above the indicator
                            (valueUp1 < Low[bar - 1] && valueUp > open) || // The Open price jumps below the indicator
                            (Close[bar - 1] < valueUp && valueUp < open) || // The Open price is in a positive gap
                            (Close[bar - 1] > valueUp && valueUp > open)) // The Open price is in a negative gap
                            tempValUp = open; // The entry/exit level is moved to Open price

                        // Lower band
                        double valueDown = adDnBand[bar - prvs]; // Current value
                        double valueDown1 = adDnBand[bar - prvs - 1]; // Previous value
                        double tempValDown = valueDown;

                        if ((valueDown1 > High[bar - 1] && valueDown < open) ||
                            // The Open price jumps above the indicator
                            (valueDown1 < Low[bar - 1] && valueDown > open) ||
                            // The Open price jumps below the indicator
                            (Close[bar - 1] < valueDown && valueDown < open) || // The Open price is in a positive gap
                            (Close[bar - 1] > valueDown && valueDown > open)) // The Open price is in a negative gap
                            tempValDown = open; // The entry/exit level is moved to Open price

                        if (IndParam.ListParam[0].Text == "Enter long at Upper Band" ||
                            IndParam.ListParam[0].Text == "Exit long at Upper Band")
                        {
                            Component[3].Value[bar] = tempValUp;
                            Component[4].Value[bar] = tempValDown;
                        }
                        else
                        {
                            Component[3].Value[bar] = tempValDown;
                            Component[4].Value[bar] = tempValUp;
                        }
                    }
                }
                else
                {
                    for (int bar = 2; bar < Bars; bar++)
                    {
                        if (IndParam.ListParam[0].Text == "Enter long at Upper Band" ||
                            IndParam.ListParam[0].Text == "Exit long at Upper Band")
                        {
                            Component[3].Value[bar] = adUpBand[bar - prvs];
                            Component[4].Value[bar] = adDnBand[bar - prvs];
                        }
                        else
                        {
                            Component[3].Value[bar] = adDnBand[bar - prvs];
                            Component[4].Value[bar] = adUpBand[bar - prvs];
                        }
                    }
                }
            }

Re: Bollinger Band Upgrade

The middle line is a Moving Average. You don't need to make the code unnecessary complex by calculating the Bands. However, if you want to do it,  see the MA application code and include it in the BB code.

Re: Bollinger Band Upgrade

I tryed this step by combining the MA and bollinger bands open close slots but it didnot work
So how to merge this MA code with the code in the previous post !!!!

if (SlotType == SlotTypes.Open || SlotType == SlotTypes.Close)
            {
                Component = new IndicatorComp[2];

                Component[1] = new IndicatorComp {Value = new double[Bars]};

                for (int bar = firstBar; bar < Bars; bar++)
                {
                    // Covers the cases when the price can pass through the MA without a signal
                    double value = movingAverage[bar - previous]; // Current value
                    double value1 = movingAverage[bar - previous - 1]; // Previous value
                    double tempVal = value;
                    if ((value1 > High[bar - 1] && value < Open[bar]) || // The Open price jumps above the indicator
                        (value1 < Low[bar - 1] && value > Open[bar]) || // The Open price jumps below the indicator
                        (Close[bar - 1] < value && value < Open[bar]) || // The Open price is in a positive gap
                        (Close[bar - 1] > value && value > Open[bar])) // The Open price is in a negative gap
                        tempVal = Open[bar];
                    Component[1].Value[bar] = tempVal; // Entry or exit value
                }
            }

Re: Bollinger Band Upgrade

Attached My trial But not working

Any help making it work !!!!


Thnx

Post's attachments

BollingerBandstst.cs 20.77 kb, 1 downloads since 2015-04-27 

You don't have the permssions to download the attachments of this post.