Bollinger Bands, created by John Bollinger in the 1980s, solve a problem that fixed indicators cannot: they adapt to volatility. Instead of static levels, the bands breathe with the market — they widen when it gets agitated and tighten when it calms down. That makes them excellent for measuring relative extremes and anticipating explosive moves.
01What Bollinger Bands are
They are three lines:
- Middle band: a simple moving average (usually 20 periods). It is the reference "fair value".
- Upper band: the average + 2 standard deviations.
- Lower band: the average − 2 standard deviations.
The key concept is standard deviation — a statistical measure of volatility. When the market is volatile, the deviation rises and the bands move apart; when it is 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.
02The main uses
1. Mean reversion (ranging market)
In a market with no trend, price tends to oscillate between the bands. Touching the lower band can signal a buy ("cheap" price); the upper band, a sell ("expensive" price). That is the basis of mean reversion strategies.
2. The squeeze (the most powerful use)
When the bands tighten sharply, it means low volatility — the market is "compressed". And here is the insight: periods of low volatility tend to be followed by periods of high volatility. The squeeze does not tell you the direction, but it warns that a strong move is building. Traders use it to get ready for a breakout.
3. "Walking the band" (strong trend)
Here is what wrecks beginners: in a strong trend, price sticks to the upper band (in an uptrend) and keeps climbing. Anyone who reads that as "overbought, I'll sell" is trading against the trend and loses. Walking the band is a sign of strength, not of reversal.
The classic mistake: "price touched the upper band, I'll sell". In a strong trend that is suicide — price can walk the band for a long time. The bands only signal reversal when the market is ranging. Always identify the regime first (see our guide to strategies and market regimes).
03Coding Bollinger Bands
//@version=5 indicator("Bandas de Bollinger", overlay=true) periodo = input.int(20, "Período") desvios = input.float(2.0, "Desvios padrão") media = ta.sma(close, periodo) desvio = ta.stdev(close, periodo) superior = media + desvios * desvio inferior = media - desvios * desvio plot(media, "Média", color=color.blue) p1 = plot(superior, "Superior", color=color.red) p2 = plot(inferior, "Inferior", color=color.green) fill(p1, p2, color=color.new(color.blue, 90)) // detects a squeeze: band width at its lowest recent level largura = (superior - inferior) / media squeeze = largura < ta.lowest(largura, 50) * 1.1 if squeeze alert("Squeeze — possível movimento forte chegando")
import pandas as pd def bollinger(precos, periodo=20, desvios=2.0): media = precos.rolling(periodo).mean() desvio = precos.rolling(periodo).std() superior = media + desvios * desvio inferior = media - desvios * desvio return media, superior, inferior media, sup, inf = bollinger(df["close"]) # relative band width (to detect squeezes) largura = (sup - inf) / media df["squeeze"] = largura < largura.rolling(50).min() * 1.1 ultimo = df["close"].iloc[-1] if ultimo <= inf.iloc[-1]: print("Preço na banda inferior — avaliar (só em lateral!)")
Shortcut: pandas-ta already has it built in: df.ta.bbands(length=20, std=2). The manual calculation shows the mechanics of the standard deviation.
Bollinger works very well with RSI
Lower band + RSI in oversold = a stronger reversal signal. See the RSI guide.
04Building strategies
- Reversion (ranging): buy at the lower band + RSI < 30, sell at the upper band + RSI > 70. Only in a market with no trend.
- Squeeze breakout: detect the squeeze, wait for a break of one of the bands, enter in the direction of the break. Captures the start of strong moves.
- Bollinger + trend: in an uptrend, use the lower band (or the middle 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 one would give on its own.
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 when things are calm. They show whether price is at an extreme relative to its own volatility.
What is the squeeze?
It is when the bands tighten sharply (low volatility). It usually precedes explosive moves, since a calm stretch tends to be followed by a strong move. It does not tell you the direction, only that something is coming.
Is touching a band a buy or a 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 does not mean it will reverse. That is why context matters more than the touch — this is mistake number 1.
Which parameters should I use?
The default is 20 periods and 2 deviations. It works in most cases. Shorter periods make it more sensitive; more deviations make the bands wider (fewer touches). Tune it with backtests, without overfitting.
Does Bollinger work for day trading?
Yes, especially the squeeze for anticipating intraday breakouts. Adjust the period to the timeframe. As always, combine it with trend and risk management.