# Bollinger band Envelope

BOLLINGER ENVELOPE SQUEEZE

Bollinger Envelopes are a variation on Bollinger Bands that focus on the extremes of price action. While Bollinger Bands are centered on a moving average, usually of closing prices, Bollinger Envelopes are anchored by the extremes: the highs and the lows.
The upper Bollinger Envelope is constructed from a moving average of the highs and the standard deviation of the highs; the lower Bollinger Envelope is constructed from a moving average of the lows and the standard deviation of the lows. The formulas are:

UpperBE = Average(high, 20) + 1.5 Ă— StandardDeviation(high, 20)
LowerBE = Average(low, 20) - 1.5 Ă— StandardDeviation(low, 20)

Since there is no middle band in the calculation, we must imply one by taking the mean of the upper and lower envelopes.

MiddleBE = (UpperBE + LowerBE) Ă· 2

Bollinger Envelopes are particularly useful in periods of extreme market action. They are also important in markets where the trading session is not well defined, and are used in the Ice Breaker trading system.

Based on the above inputs I'm trying hard to make amibroker formula from last 10 days. Not getting properly.

Lower = Avg(BBandBot(Low, 20, -1.5)) * StDev(Low, 20);
upper = Avg(BBandTop(Low, 20, -1.5)) * StDev(Low, 20);

Plot(Lower, "LBB", styleLine);
Plot(upper, "UBB", styleLine);

Program showing error at Avg; if I removed avg formula looks like...

Lower = (BBandBot(Low, 20, -1.5)) * StDev(Low, 20)/20;
upper = (BBandTop(Low, 20, -1.5)) * StDev(Low, 20)/20;
Plot(Lower, "LBB", styleLine);
Plot(upper, "UBB", styleLine);

Not successful.

I request you to all, anybody correct the code.

Thanks with regards,

Moderator comment: Your post was INCORRECTLY formatted and I had to fix it. Next time follow the forum rules and format message correctly!

@dragon Firstly, you made a mistake (probably from copy & paste) that you are using "Low" for both your Upper and Lower calculations

Lower = Avg(BBandBot(Low, 20, -1.5)) * StDev(Low, 20);
upper = Avg(BBandTop(Low, 20, -1.5)) * StDev(Low, 20);

You need to learn about the different functions in AmiBroker. The functions to learn are "BBandBot", "BBandTop", and "ma".

I've made a couple of versions of what you appear to be after. Two versions of the Top and two versions of the bottom. They should be the equivalent but I am not sure why the two versions don't match up for the "Low" but they do for the "High" ? That's as far as I've gotten so far so get on it and let us know how it goes.

Upper = BBandTop( High, 20, 1.5 );
Lower = BBandBot( Low, 20, -1.5 );

UpperBE = ma( high, 20 ) + 1.5 * StDev( high, 20 );
LowerBE = ma( low, 20 ) - 1.5 * StDev( low, 20 );

Plot( C, "Close", ParamColor( "Color", colorDefault ), styleNoTitle | ParamStyle( "Style", styleThick ) | GetPriceStyle() );
Plot( Upper, "UBB", colorWhite, styleDashed );
Plot( Lower, "LBB", colorWhite, styleDashed );
Plot( UpperBE, "UpperBE", colorRed, styleDots );
Plot( LowerBE, "LowerBE", colorRed, styleDots );

Filter = 1;

1 Like

They donâ€™t match because of

Lower = BBandBot( Low, 20, -1.5 );

Lower = BBandBot( Low, 20, 1.5 );
2 Likes

@fxshrat Thanks! I just got finished telling the other guy to review the functions and then I go and make a newbie mistake like that . A nice reminder that it helps to re-read the User Guide when I get unexpected results.

so for @dragon here is my corrected code,

Upper = BBandTop( High, 20, 1.5 );
Lower = BBandBot( Low, 20, 1.5 );

// built in AmiBroker functions BBandTop and BBandBot
// are doing the equivalent of these calculations

UpperBE = ma( high, 20 ) + 1.5 * StDev( high, 20 );
LowerBE = ma( low, 20 ) - 1.5 * StDev( low, 20 );

Plot( C, "Close", ParamColor( "Color", colorDefault ), styleNoTitle | ParamStyle( "Style", styleThick ) | GetPriceStyle() );
Plot( Upper, "UBB", colorWhite, styleDashed );
Plot( Lower, "LBB", colorWhite, styleDashed );
Plot( UpperBE, "UpperBE", colorRed, styleDots );
Plot( LowerBE, "LowerBE", colorRed, styleDots );

Filter = 1;