◆ New — Strategy Validator, Code Fixer & Prop Compliance Checker are live. Try one free →
Home / Indicators / Bollinger Bands
Volatility indicator

Bollinger Bands

A moving average wrapped in volatility-based bands that widen and narrow as price action calms or churns.

Illustrative diagram — not live market data.

What it is

Bollinger Bands are a volatility indicator developed by John Bollinger. They consist of three lines plotted on the price chart: a middle band (a simple moving average, by default over 20 periods) and an upper and lower band placed a set number of standard deviations away from that average (by default 2). Because the bands are derived from the standard deviation of price, they expand when price becomes more volatile and contract when it becomes calmer. They are an educational analysis tool only, not a buy/sell system, and no indicator can predict future price. All trading carries risk of loss.

How it works

The middle line is a simple moving average of recent closing prices, which smooths out short-term noise to show the general direction. The upper and lower bands are then drawn by measuring how spread out recent prices have been (the standard deviation over the same lookback) and shifting the average up and down by a multiple of that spread, usually two times. When recent prices swing widely, the standard deviation grows and the bands move farther apart; when prices stay in a tight range, the standard deviation shrinks and the bands squeeze together. So the distance between the bands is essentially a running picture of recent volatility, while the middle line tracks the average. All of this is calculated from past closes, so the bands describe what has already happened rather than forecast what comes next.

How traders read it

Common settings

Length 20 with a 2.0 standard-deviation multiplier on closing price is the classic default. Shorter lengths (e.g. 10) react faster but are noisier; longer lengths (e.g. 50) are smoother but slower. Some traders adjust the multiplier (e.g. 1.5 to 2.5) to make band touches more or less frequent. These are conventions, not recommended values.

Strengths

Pitfalls to watch

Pine v6 example

//@version=6
indicator("Bollinger Bands", overlay = true)

length = input.int(20, "Length", minval = 1)
mult   = input.float(2.0, "StdDev Multiplier", minval = 0.1)
src    = input.source(close, "Source")

basis = ta.sma(src, length)
dev   = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev

plot(basis, "Basis", color = color.orange)
p2 = plot(upper, "Upper", color = color.teal)
p3 = plot(lower, "Lower", color = color.teal)
fill(p2, p3, color = color.new(color.teal, 90), title = "Background")

Pro tip: Watch the band width itself, not just where price sits. A prolonged squeeze tells you recent volatility is unusually low, and historically such periods have sometimes preceded larger moves, but it gives no clue about direction or timing. Treat any subsequent breakout as something to confirm with other evidence and proper risk control, never as a guarantee.

Built an indicator from this? Run it through the Validator to catch look-ahead bias and repainting, or convert a strategy to Pine Script.

Educational only — not financial advice, not a recommendation to trade. No indicator is predictive; trading involves substantial risk of loss.

Catch the bug that compiles.Run auditGet Pro