Bollinger Bands strategy: squeeze, bounce and breakout rules

Bollinger Bands wrap price in a volatility envelope: a moving average with bands set a number of standard deviations above and below. They power two opposite strategies — fade the edges in a range, or trade the breakout when the bands squeeze. This guide gives the settings, the rules, the code, and the backtest discipline.

On this page
  1. What Bollinger Bands are
  2. The squeeze
  3. The mean-reversion bounce
  4. The code
  5. FAQ

What Bollinger Bands actually measure

A Bollinger Band is a 20-period simple moving average (the middle band) with an upper and lower band placed two standard deviations away. Because standard deviation expands when price gets volatile and contracts when it calms down, the bands breathe with the market. That single property — adaptive width — is what makes them useful for both range and breakout systems.

equitytime steady compoundingdeep drawdown
A smooth equity curve compounds; a volatile one with deep drawdowns risks ruin even at the same average return.

The squeeze: low volatility precedes expansion

When the bands narrow sharply, volatility is unusually low — a "squeeze." Markets cycle between quiet and active, so a tight squeeze often precedes a strong directional move. The squeeze itself does not tell you direction; it tells you a move is likely coming. Breakout traders wait for price to close outside the bands after a squeeze and trade in that direction, ideally with a volume or trend confirmation to cut false breaks.

The mean-reversion bounce

In a sideways market, price tends to revert toward the middle band. A classic mean-reversion rule buys when price touches the lower band and sells near the middle or upper band. The danger: in a strong trend, price can "walk the band," hugging the upper band for a long time while a naive fader keeps shorting into strength and losing. That is why a Bollinger bounce bot needs a trend filter that switches it off when the market is clearly trending.

The code

python · bbands.pyimport statistics as st
def bbands(closes, n=20, k=2):
    window = closes[-n:]
    mid = sum(window)/n
    sd = st.pstdev(window)
    return mid - k*sd, mid, mid + k*sd  # lower, mid, upper

low, mid, up = bbands(closes)
if price <= low and trending is False: signal = 'buy'  # bounce only in a range

Whatever variant you choose, validate it in the backtester with realistic costs. Band touches are frequent, so a Bollinger bot trades a lot — and fees plus slippage quietly eat high-frequency edges.

Not financial advice. This content is educational. Automated and algorithmic trading carries a real risk of financial loss. Never trade money you cannot afford to lose. Review the SEC investor.gov and CFTC resources before trading.

Frequently asked questions

What are the best Bollinger Band settings?

The default is a 20-period moving average with bands at 2 standard deviations. Shorter periods react faster but give more false signals; wider bands (2.5–3 SD) trigger less often. As with any indicator, robustness across nearby settings matters more than the single best-looking one.

Is the Bollinger squeeze reliable?

The squeeze reliably signals that volatility is low and a larger move is likely, but it does not predict direction. Traders pair it with a breakout confirmation. False breakouts are common, so risk management and a confirmation filter are essential.

Can Bollinger Bands be automated in a bot?

Yes. The calculation is simple — a moving average and standard deviation — so it is easy to code in Python or Pine Script. The hard part is the trend filter that prevents the bounce strategy from fighting strong trends.

Why does price 'walk the band'?

In a strong trend, price can ride along the upper or lower band for many bars. A mean-reversion strategy that shorts every upper-band touch will lose repeatedly during such moves, which is why a trend regime filter is critical.

MB

Mustafa Bilgic

Algorithmic trading practitioner · Founder, AITradingBot.us

Mustafa builds and backtests automated trading systems and writes about them without the hype. Every tool on this site is free and runs entirely in your browser.