Volatility Indicators

Bollinger Bands: Volatility & Mean Reversion

In this page: what Bollinger Bands is, how it works, when to use it, a practical example with code, and a bonus tip.

📖 7 min read

📝 1,353 words

🏷️ Volatility Indicators

Bollinger Bands on a price chart: illustration of the indicator and how it is used in technical analysis
Bollinger Bands – chart illustration

Bollinger Bands Indicator Explanation

Bollinger Bands are a popular volatility-based technical indicator used in algorithmic trading strategies to assess price extremes and potential reversals. Developed by John Bollinger in the 1980s and detailed in his book "Bollinger on Bollinger Bands" (2001), the indicator consists of three lines: a simple moving average (SMA) in the middle, and two bands (upper and lower) placed at a set number of standard deviations above and below the SMA. By default, these bands are typically set two standard deviations apart from a 20-period SMA.

How Bollinger Bands Works: Bollinger Bands calculate the middle band as a simple moving average (typically 20 periods) of the closing price. The upper and lower bands are then calculated by adding and subtracting a multiple of the standard deviation (typically 2) from the middle band. The bands expand when volatility increases and contract when volatility decreases, providing a dynamic view of price action relative to recent volatility. This statistical approach uses standard deviation to measure price dispersion around the mean, creating adaptive trading bands that respond to changing market conditions.

When to Use Bollinger Bands:

  • Mean Reversion Trading: Bollinger Bands are most effective in sideways or ranging markets for spotting mean-reversion opportunities when price touches or breaches the bands, as prices tend to revert to the mean in such conditions.
  • Breakout Identification: In trending markets, Bollinger Bands can help identify breakouts when price moves outside the bands with strong momentum, indicating potential continuation of the trend.
  • Volatility Assessment: The width of the bands indicates market volatility—narrow bands (squeeze) suggest low volatility and potential breakout, while wide bands suggest high volatility and potential reversal.

Advantages:

  • Adapts dynamically to market volatility, expanding and contracting with market conditions, making it responsive to changing market environments.
  • Useful for spotting breakouts, reversals, or price consolidations in real time, providing multiple trading signals.
  • Helps define high- and low-price zones based on statistical analysis of recent price action, using standard deviation as a measure of normal price distribution.

Limitations:

  • Can produce false signals in highly trending markets where prices can "walk the band" for extended periods, requiring trend confirmation.
  • Requires confirmation with other tools like momentum indicators or volume analysis to improve accuracy and reduce false signals.
  • Band widening or narrowing may lag during rapid market shifts, potentially missing early signals as the indicator is based on historical data.

In summary, Bollinger Bands are a versatile indicator in a trading strategy, helping traders identify potential entry and exit points based on volatility and price behavior relative to recent market conditions. For comprehensive understanding, refer to John Bollinger's "Bollinger on Bollinger Bands" (2001) (opens in a new tab), Investopedia's Bollinger Bands guide (opens in a new tab), TradingView's Bollinger Bands documentation (opens in a new tab), and academic research on statistical volatility analysis in technical trading published in journals such as the Journal of Financial Markets and International Review of Financial Analysis.

Practical Example: Using Bollinger Bands in a Trading Strategy

The Bollinger Bands indicator is a volatility-based tool used to identify overbought and oversold conditions, potential breakouts, and mean-reversion opportunities. In a trading strategy, Bollinger Bands help traders make decisions based on price position relative to recent volatility.

Scenario: You're creating a mean-reversion strategy for Bitcoin (BTC/USDT) on a 1-hour chart. You want to buy when the price is oversold (below the lower band) and sell when it's overbought (above the upper band), assuming prices will return to the mean.

Strategy Logic:

  • Use a 20-period Bollinger Bands with 2 standard deviations to define volatility-based price zones.
  • Buy signal: When the price closes below the lower Bollinger Band (oversold condition), and volume is above average (indicating potential reversal interest).
  • Sell signal: When the price closes above the upper Bollinger Band (overbought condition), and there is a bearish candlestick pattern or volume spike confirming the reversal.

Backtrader Example:

python
import backtrader as bt

class BollingerBandsStrategy(bt.Strategy):
    params = dict(
        bb_period=20,
        bb_devfactor=2.0,
        volume_period=20
    )
    
    def __init__(self):
        self.bb = bt.ind.BollingerBands(
            period=self.p.bb_period,
            devfactor=self.p.bb_devfactor
        )
        self.volume_sma = bt.ind.SMA(
            self.data.volume,
            period=self.p.volume_period
        )
        
    def next(self):
        if not self.position:
            # Buy when price closes below lower band and volume is above average
            if (self.data.close[0] < self.bb.lines.bot[0] and 
                self.data.volume[0] > self.volume_sma[0]):
                self.buy()
        else:
            # Sell when price closes above upper band
            if self.data.close[0] > self.bb.lines.top[0]:
                self.sell()

# Usage
cerebro = bt.Cerebro()
cerebro.addstrategy(BollingerBandsStrategy)

Expected Outcome: By using Bollinger Bands, your strategy catches short-term price reversals when the market becomes overextended. A buy signal suggests the price is undervalued relative to recent volatility, offering a potential bounce. Conversely, a sell signal suggests the price may be overextended and due for a pullback.

💡 Bonus Tip

Always confirm Bollinger Band signals with additional indicators like RSI or trend direction to reduce false signals and improve success rates. In strong trends, consider using Bollinger Bands for breakout strategies rather than mean-reversion.

Using Bollinger Bands ensures your strategy adapts to changing market volatility, improving entry and exit timing based on statistical price analysis.

Band mean reversion (20, 2): history and rules

Who and when: The bands: John Bollinger; his book is from 2001. The reversion rule: common practice, and not his.

John Bollinger developed the bands that carry his name and wrote a book about them in 2001. The middle band is an average of the price, 20 bars by default. An upper and a lower band sit 2 standard deviations away, so they widen when the market is volatile and narrow when it is quiet. On his own site Bollinger says the bands give a relative definition of high and low.

Many traders turned that into a reversion rule: buy when the price closes below the lower band and hold until it has moved back up. That rule is common practice, not Bollinger's.

The rule as the source states it

The author: the bands define what is relatively high and low; the defaults are 20 periods and 2 standard deviations; a touch of the upper band is not by itself a sell signal, and a touch of the lower band is not by itself a buy signal. An education page: prices tend to bounce inside the bands, from one band to the other.

Our version

Bollinger Bands (20, 2) on the close, simple average, 1-hour bars of a currency pair. Buy when the close is below the lower band. Sell short when the close is above the upper band. An opposite signal closes the trade and reverses it, so a bought trade ends at the upper band and a sold one at the lower band.

How ours differs

  • Ours treats a close beyond a band as a signal, which the author advises against.
  • Ours holds until the other band (the move from band to band the education page describes), not until the middle band.
  • Like every library file, ours also adds the builder's default stop, position size and account limits (Steps 5 and 6). You can change them in the form.

This rule goes against the bands' author. John Bollinger's own rules say that a touch of a band is not a signal by itself; this rule trades exactly that. For his own reading of a close outside the bands, see the band breakout strategy.

Sources: John Bollinger's site: his rules for the bands (opens in a new tab); Open Library: John Bollinger's book on his bands (2001) (opens in a new tab); Fidelity Learning Center: What Are Bollinger Bands? (opens in a new tab).

Who created the Band mean reversion (20, 2) strategy, and what are its rules?

The bands: John Bollinger; his book is from 2001. The reversion rule: common practice, and not his. Bollinger Bands (20, 2) on the close, simple average, 1-hour bars of a currency pair. Buy when the close is below the lower band. Sell short when the close is above the upper band. An opposite signal closes the trade and reverses it, so a bought trade ends at the upper band and a sold one at the lower band. Being well known says nothing about how a strategy will do. Test it on your own data.

Can be built on the Free plan. Open in the builder →

Being well known says nothing about how a strategy will do. Test it on your own data.

Build a strategy with Bollinger Bands — no code

Step-by-step guides that use this indicator in a complete strategy.

MetaTrader 5 · MQL5

TradingView · Pine Script

Each platform has its own builder form — build this recipe in the MQL5 form or the Pine form.