Bollinger Mean Reversion (Mean reversion)

Buys when price closes below the lower Bollinger Band (20-bar, 2σ) and sells when it recovers to the middle band — a mean reversion back to the 20-bar average.

How It Works

  1. Each bar, compute the 20-bar simple moving average of the close and its Bollinger Bands two standard deviations above and below.
  2. Buy when the close drops below the lower band — an unusually stretched move to the downside.
  3. Sell as soon as the close recovers above the middle band (the 20-bar average itself) — taking the quicker, more reliable half of the bounce instead of waiting for the far band.

Worked example. With bands at 96 / 100 / 104, a close at 95.5 buys. When price recovers and closes at 100.4 — back above the 20-bar average — the trade exits with roughly a 5% gain.

The Math Behind The Indicators

Everything runs on closing prices of the traded timeframe: P is a close, Pt today's close, and N counts bars — one bar is one candle of that timeframe, so 20 bars on a 1h chart is 20 hours.

Simple Moving Average (SMA)
The plain average of the last N closing prices: add them up, divide by N. It smooths out bar-to-bar noise so the underlying direction is easier to see — a rising SMA means recent prices sit above where they used to be.
2026-07-23T00:16:15.981930 image/svg+xml Matplotlib v3.11.1, https://matplotlib.org/
Example: With N = 3 and closes 100, 102, 104 the SMA is (100 + 102 + 104) / 3 = 102.
Bollinger Bands
A 20-bar SMA with an envelope two standard deviations above and below it. The standard deviation σ measures how far closes have recently strayed from their average, so the bands widen when the market is choppy and tighten when it is calm — a close outside a band is a statistically unusual move.
2026-07-23T00:16:15.996885 image/svg+xml Matplotlib v3.11.1, https://matplotlib.org/
Example: If the last 20 closes average 100 and typically stray about 1.5 from it (σ = 1.5), the bands sit at 100 ± 3, i.e. 97 and 103. A close at 96.5 is below the lower band — unusually cheap relative to the recent range.

Example Chart

Real Data — Score 27 / 100

Metrics Per Trade

Final Metrics

Scores

Resampled Data — Score 27 / 100

Metrics Per Trade

Final Metrics

Scores