How it works
Bollinger Bands answer a question that a plain moving average cannot: is this distance from the average large or small for this market, right now? A stock that routinely swings three percent a day is not doing anything unusual when it closes two percent above its mean, while the same excursion in a sleepy utility would be an event. By scaling the envelope with the standard deviation of the same window that produced the average, the bands express distance in the market's own units instead of in dollars.
The construction is deliberately simple. A middle band, normally a twenty-period simple moving average, sets the reference. The standard deviation of those same twenty closes measures how tightly the recent data has clustered around that reference, and the outer bands are placed a fixed number of deviations either side, conventionally two. Both quantities are recalculated on every bar, so the envelope drifts with the trend and breathes with volatility at the same time. When the market goes quiet the deviation collapses and the bands pull in toward the average; when it becomes disorderly they flare apart within a handful of bars.
In practice traders read the bands three ways. The width itself is the volatility regime, and because volatility clusters and mean reverts, unusually narrow bands are a statement about what is likely to happen next even though they say nothing about direction. The position of the close inside the channel describes how stretched the current move is. And the behaviour at the edge separates regimes: in a range, touches of the outer band tend to be followed by a return to the middle, while in a strong trend price walks the band, printing bar after bar against the upper edge with the average rising underneath it. That difference is the single most useful thing on the plot, and it is also the thing beginners most often get backwards.
Against its neighbours, Bollinger Bands sit between a fixed percentage envelope and a true-range channel. Percentage envelopes ignore volatility entirely and therefore need constant hand-tuning. Keltner Channels use average true range instead of standard deviation, which makes them smoother and less reactive because a single violent bar moves ATR far less than it moves a squared-deviation estimate. Donchian channels ignore the centre altogether and track raw extremes. Bollinger is the most statistically flavoured of the four and the most responsive, which is a virtue in a compression study and a liability when one outlier bar reprices the whole envelope.
Calculation
The arithmetic in words, in the order it happens.
Compute the middle band as the moving average of the last N closes, conventionally a 20-period simple moving average. Over the same 20 closes compute the standard deviation: the square root of the average squared deviation from that mean, using the population form that divides by N rather than by N minus 1, which is what charting packages ship. The upper band is the middle band plus K standard deviations, the lower band is the middle band minus K, with K conventionally 2. Every value is recomputed from scratch on each new bar from the same rolling window, so the average and the width update together.
Source
An AlgoBeamScript implementation of the formula above, written by us from the arithmetic so the code and the calculation agree line for line.
Runs unchanged on the platform and in the AlgoBeamTS runtime. The language reference is in the documentation.
Inputs
Defaults are the values most charting packages ship with. They are conventions, not optimal settings — the right length depends on your instrument and your holding period.
| Input | Default | What it changes |
|---|---|---|
| Length | 20 | Number of bars in both the average and the deviation. Shorter lengths hug price and make band touches routine; longer ones produce a slower centre line and an envelope that reacts to a volatility change only after many bars have passed. |
| Standard deviations | 2 | Half-width of the envelope in deviation units. Raising it to 2.5 or 3 makes touches rare and turns the bands into an outlier detector; dropping toward 1.5 makes them a routine oscillation boundary suitable for mean-reversion work on quiet instruments. |
| Source | Close | The price series fed to the average and the deviation. Close is standard. Typical price, the average of high, low and close, produces a slightly steadier centre on instruments with erratic closing prints. |
| Offset | 0 | Shifts the plotted bands forward or backward in time. Useful only for visual alignment studies; a positive offset draws bands over bars that did not contribute to them, so never build a rule on it. |
How to read it
What practitioners take from the plot. Read these as descriptions of market state, not as entry signals.
- Bands contract into a narrow ribbon
- Realised volatility has fallen well below its recent norm. Volatility mean reverts, so expansion is likely, but the bands give no clue which direction it takes.
- Price walks the upper band across many bars
- A trend strong enough that each new close is an outlier relative to the last twenty. This is continuation behaviour, not an overbought warning.
- Close pushes outside a band then closes back inside
- A rejected excursion. In a ranging market this is the classic reversion setup; in a trending one it is often just a pause before the walk resumes.
- A new price high made without a new high outside the band
- The second push is less extreme relative to current volatility than the first, a common precursor to a stall even though it is not a timing signal.
- Bands flare apart on a single bar
- A shock has entered the window. Expect the envelope to stay artificially wide for roughly the length of the lookback as that bar works through it.
Limitations
Where this indicator misleads. None of these are fixed by a better parameter.
- The familiar claim that ninety-five percent of prices should fall inside two deviations assumes normally distributed independent returns. Real returns are fat-tailed and serially dependent, and the deviation is estimated from the same twenty observations it is describing, so excursions beyond the bands are far more common than the textbook figure implies.
- In a sustained trend the bands generate a continuous stream of upper-band touches, and any rule that fades them is systematically short the strongest part of the move. Band touches must be filtered by a regime read before they mean anything.
- One outlier bar inflates the standard deviation for the whole lookback and then drops out abruptly, which makes the envelope jump for reasons that have nothing to do with current conditions.
- The bands lag by construction: the centre is an average of past closes and the width reflects volatility that has already been realised, so the envelope widens after the move, never before it.
Educational reference. This page explains how an indicator is built and how it is commonly read. It is not investment advice, not a recommendation and not a signal service. No indicator is profitable on its own — each is a way of describing a market, and any rule built on one has to be tested with realistic costs before it is traded.