Bollinger Bands

Description
Bollinger Bands are a technical trading tool created by John Bollinger in the early 1980s.

The purpose of Bollinger Bands is to provide a relative definition of high and low.
Bollinger Bands consist of a set of three plots drawn in relation to securities prices.

The middle band is a measure of the intermediate-term trend, usually a simple moving average, that serves as the base for the upper and lower bands.

The interval between the upper and lower bands and the middle band is determined by volatility, typically the standard deviation of the same data that are used for the average.

The default parameters are 20day (periods) and two standard deviations:

Middle Bollinger Band = 20-Day simple moving average
Upper Bollinger Band = Middle Bollinger Band + 2 * 20-period standard deviation
Lower Bollinger Band = Middle Bollinger Band - 2 * 20-period standard deviation

The majority of a security's price action will occur within the range of the Bollinger Bands, but prices can remain overbought or oversold for an extended period of time.

In periods of considerable price changes (i.e. of high volatility) the bands widen leaving a lot of room to the prices to move in. During standstill periods, or the periods of low volatility the band contracts keeping the prices within their limits.


Calculation:
Bollinger bands are formed by three lines. The middle line (ML) is a usual Moving Average.
ML = SUM[CLOSE, N]/N

The top line, TL, is the same as the middle line a certain number of standard deviations (D) higher than the ML.
TL = ML+(D*StdDev)

The bottom line (BL) is the middle line shifted down by the same number of standard deviations.
BL = ML-(D*StdDev)

Where:
N is the number of periods used in calculation;
SMA = Simple Moving Average;
StdDev = means Standard Deviation.
StdDev = SQRT(SUM[(CLOSE-SMA(CLOSE,N))^2,N]/N)

It is recommended to use 20-period Simple Moving Average as the middle line, and plot top and bottom lines two standard deviations away from it.

Conclusions
Even though Bollinger Bands can help generate buy and sell signals, they are not designed to determine the future direction of a security.

Bollinger Bands serve two primary functions:
-To identify periods of high and low volatility
-To identify periods when prices are at extreme, and possibly unsustainable, levels.

Remember that buy and sell signals are not given when prices reach the upper or lower bands. Such levels merely indicate that prices are high or low on a relative basis.

NinjaScript
Bollinger Bands come programmed into NinjaTrader.

Suggestions
When using Bollinger Bands, I usually plot the 20-day moving average with both the first and second standard deviations. This way, if a security is trading between the first and second bands, you can see clearly if it's in an up trend or a down trend. If the security is between the moving average and the first standard deviation, then it is considered to be in no man's land and I would wait for a clearer signal before trading.