⬡ INDICATOR · WITH CODE · 11 MIN READ

Bollinger Bands: volatility and reversion.

The indicator that measures whether price is "expensive" or "cheap" relative to its own volatility — with the squeeze concept that precedes explosive moves, plus ready-to-use code.

By the RoboTraderIA Team· updated May 2026· intermediate level

Bollinger Bands, created by John Bollinger in the 1980s, solve a problem that fixed indicators can't: they adapt to volatility. Instead of static levels, the bands breathe with the market — they open when it gets agitated, close when it calms down. That makes them excellent for measuring relative extremes and anticipating bursts of movement.

01What Bollinger Bands are

They're three lines:

  • Central band: a simple moving average (usually 20 periods). It's the "fair value" reference.
  • Upper band: the average + 2 standard deviations.
  • Lower band: the average − 2 standard deviations.

The key concept is the standard deviation — a statistical measure of volatility. When the market is volatile, the deviation increases and the bands move apart; when it's calm, they move closer together. Statistically, about 95% of prices stay within 2 standard deviations, so touching a band means price is at a relative extreme.

upper average (20) lower squeeze (narrow bands)
The bands narrow in the squeeze (gold zone) and expand with volatility. Price oscillates between them.

02The main uses

1. Mean reversion (ranging market)

In a trendless market, price tends to oscillate between the bands. Touching the lower band can signal a buy (price "cheap"); the upper, a sell (price "expensive"). It's the basis of mean-reversion strategies.

2. The squeeze (the most powerful use)

When the bands narrow sharply, it means low volatility — the market is "compressed." And here's the insight: periods of low volatility tend to be followed by periods of high volatility. The squeeze doesn't tell you the direction, but it warns that a strong move is forming. Traders use it to prepare for a breakout.

3. "Walking the band" (strong trend)

Here's what trips up beginners: in a strong trend, price hugs the upper band (in an uptrend) and keeps rising. Anyone who reads this as "overbought, I'll sell" trades against the trend and loses. Walking the band is a sign of strength, not reversal.

The classic mistake: "price touched the upper band, I'll sell." In a strong trend that's suicide — price can walk the band for a long time. The bands only signal reversal in a ranging market. Always identify the regime first (see our guide to strategies and regimes).

03Coding Bollinger Bands

Pine Script (TradingView)
//@version=5
indicator("Bollinger Bands", overlay=true)

period = input.int(20, "Period")
devs   = input.float(2.0, "Standard deviations")

basis = ta.sma(close, period)
dev   = ta.stdev(close, period)
upper = basis + devs * dev
lower = basis - devs * dev

plot(basis, "Basis", color=color.blue)
p1 = plot(upper, "Upper", color=color.red)
p2 = plot(lower, "Lower", color=color.green)
fill(p1, p2, color=color.new(color.blue, 90))

// detect a squeeze: band width near its recent low
width = (upper - lower) / basis
squeeze = width < ta.lowest(width, 50) * 1.1
if squeeze
    alert("Squeeze — a strong move may be coming")
Python (with pandas)
import pandas as pd

def bollinger(prices, period=20, devs=2.0):
    basis = prices.rolling(period).mean()
    dev   = prices.rolling(period).std()
    upper = basis + devs * dev
    lower = basis - devs * dev
    return basis, upper, lower

basis, upper, lower = bollinger(df["close"])

# relative band width (to detect a squeeze)
width = (upper - lower) / basis
df["squeeze"] = width < width.rolling(50).min() * 1.1

last = df["close"].iloc[-1]
if last <= lower.iloc[-1]:
    print("Price at the lower band — consider (ranging only!)")

Shortcut: pandas-ta has it ready: df.ta.bbands(length=20, std=2). The manual calculation shows the mechanics of the standard deviation.

Bollinger pairs very well with RSI

Lower band + RSI oversold = a stronger reversal signal. See the RSI guide.

See the RSI guide →

04Building strategies

  • Reversion (ranging): buy at the lower band + RSI < 30, sell at the upper + RSI > 70. Only in a trendless market.
  • Squeeze breakout: detect the squeeze, wait for one of the bands to break, enter in the direction of the break. Captures the start of strong moves.
  • Bollinger + trend: in an uptrend, use the lower band (or the central average) as a re-entry zone on pullbacks.

Classic combination: Bollinger Bands (volatility) + RSI (momentum) + a trend moving average. The three together filter out most of the false signals each would generate alone.

05Frequently asked questions

What are Bollinger Bands?

Three lines: a central moving average (20) and two bands at 2 standard deviations above and below. They expand with volatility and contract in calm. They show whether price is at an extreme relative to its own volatility.

What is the squeeze?

It's when the bands narrow sharply (low volatility). It often precedes explosive moves, since calm tends to be followed by strong movement. It doesn't tell the direction, only that something is coming.

Is touching a band a buy or sell?

It depends on the regime. In a range, touching the lower band can be a buy (reversion). In a strong trend, price "walks the band" and a touch doesn't mean a reversal. That's why context matters more than the touch — it's the #1 mistake.

Which parameters should you use?

The default is 20 periods and 2 deviations. It works in most cases. Smaller periods make it more sensitive; more deviations make the bands wider (fewer touches). Adjust via backtest, without overfitting.

Does Bollinger work in day trading?

Yes, especially the squeeze for anticipating intraday breakouts. Adjust the period to the timeframe. As always, combine with trend and risk management.