Bollinger band reversion strategy
On ES futures, the Bollinger band reversion strategy lost $99,536 after costs and ran a $100,000 account down to its margin on October 4, 2021. The run stops there.
Mean reversionIntraday5-minute barsBacktested Nov 6, 2026
Bollinger band reversion backtest, the result
Contract
E-mini S&P 500
-
−$99.5K
Net after costs
After $143,211 in fees and slippage
-
1 of 6
Years that made money
January 2016 to October 2021
-
−$101K
Largest drawdown
Peak to trough, 1 contract
-
−$20
Average trade
5,040 trades
Net after costs by month, January 2016 to October 2021.
Bollinger band reversion rules
Buy a close below the lower Bollinger band, sell a close above the upper one, and exit at the 20-bar mean.
A drawing of the rules on a made-up day, not a result.
- The middle band is the 20-bar mean of the five-minute close and the bands lie 2 standard deviations (population) either side, on every close of the Globex session.
- A close above the upper band sells short and a close below the lower band buys, on bars that close in the day session before 15:45 New York.
- The position is closed when a one-second close reaches the middle band, or at 15:45 New York.
- Decides on
- 5-minute bars
- Holds
- Nothing overnight
- Parameters
- bands 2, open minute 570, exit minute 945, bar minutes 5
Results by year
It made money in 1 of 6 years on ES. Its best year was 2020, +$12,945, and its worst 2018, −$28,286. The account was closed out on October 4, 2021, so the years stop there.
| Year | Net | Trades | Win rate | Drawdown | Buy and hold |
|---|---|---|---|---|---|
| 2016 | −$21,824 | 885 | 57% | −$23,665 | +$11,497 |
| 2017 | −$19,567 | 875 | 59% | −$20,486 | +$21,936 |
| 2018 | −$28,286 | 883 | 62% | −$33,233 | −$8,589 |
| 2019 | −$13,750 | 864 | 63% | −$17,271 | +$35,436 |
| 2020 | +$12,945 | 889 | 65% | −$28,172 | +$27,761 |
| 2021, Jan to Oct | −$29,054 | 644 | 61% | −$29,054 | +$51,361 |
Bollinger band reversion backtest results
On ES it made $43,675 before costs. Fees and slippage took $143,211, more than all of it.
- Net = before costs − fees − slippage
- ES: $43,675 − $17,211 − $126,000 = −$99,536
The whole interval is under zero: after costs, the average trade lost money.
Bollinger band reversion code and Pine Script
The strategy as the backtest ran it, and the Pine Script our compiler wrote from it for TradingView.
1from atlantive import BUY, NEW_YORK, SELL, Bars, Rolling, Session, Strategy2 3 4class BollingerBandReversion(Strategy):5 """Bollinger band (20, 2) reversion on five-minute bars, traded in the New York day session.6 7 The middle band is the 20-bar mean of the five-minute close and the bands lie 2 standard8 deviations (population) either side, on every close of the Globex session. A close above the9 upper band sells short and a close below the lower band buys, on bars that close in the day10 session before 15:45. The position is closed when a one-second close reaches the middle band11 (as of the last five-minute close), or at 15:45. The clock is one-second bars; the five-minute12 bars are built from them, by their start time.13 """14 15 data = "bars"16 17 class Params:18 bands: float = 2.019 open_minute: int = 57020 exit_minute: int = 94521 bar_minutes: int = 522 clip: int = 123 24 class State:25 clock: Session(zone=NEW_YORK)26 bars: Bars(interval_ns=1_000_000_000)27 closes: Rolling(window=20)28 mid: float29 bar_key: int30 bar_minute: int31 bar_close: float32 33 def on_event(self, view, ev, orders):34 self.clock.update(ev)35 if not self.bars.update(ev):36 return37 minute = self.clock.prev_minute38 second = self.clock.prev_second39 day = self.clock.prev_day40 close = float(self.bars.prev_close)41 key = (day * 1440 + minute) // 542 if key != self.bar_key:43 if self.bar_key != 0:44 # The five-minute bar starting at bar_minute closed at bar_close.45 self.closes.update(self.bar_close)46 if self.closes.ready == 1:47 self.mid = self.closes.mean()48 width = self.p.bands * self.closes.std()49 ends = self.bar_minute + self.p.bar_minutes50 in_day = self.bar_minute >= self.p.open_minute and ends < self.p.exit_minute51 if in_day and view.position == 0 and width > 0:52 if self.bar_close > self.mid + width:53 orders.ioc(side=SELL, qty=self.p.clip)54 elif self.bar_close < self.mid - width:55 orders.ioc(side=BUY, qty=self.p.clip)56 self.bar_key = key57 self.bar_minute = minute - minute % 558 self.bar_close = close59 late = second + 1 >= self.p.exit_minute * 60 or minute < self.p.open_minute60 if view.position < 0:61 if close <= self.mid or late:62 orders.ioc(side=BUY, qty=abs(view.position))63 elif view.position > 0:64 if close >= self.mid or late:65 orders.ioc(side=SELL, qty=abs(view.position)) 1//@version=62// BollingerBandReversion, exported from Atlantive.3// Chart simulation: decisions use completed bars; market orders fill at the next bar open.4// Native fills, fees, data gaps and session boundaries can differ. Re-test on the target symbol.5// Use standard time-based candles and the strategy's timeframe, not synthetic chart prices.6// Pine v6 trims old trade records at its order limit; the strategy keeps calculating.7// Margin is explicitly disabled to retain the native signal simulation's sizing.8strategy("BollingerBandReversion", overlay=true, initial_capital=100000.0, commission_type=strategy.commission.cash_per_contract, commission_value=1.68, default_qty_type=strategy.fixed, default_qty_value=1, calc_on_every_tick=false, process_orders_on_close=false, slippage=0, margin_long=0, margin_short=0)9 10if timeframe.in_seconds() != 111 runtime.error("BollingerBandReversion was exported for the 1 second timeframe; set the chart to 1S.")12 13bands = input.float(2.0, "bands")14open_minute = input.int(570, "open_minute", minval=-9007199254740991, maxval=9007199254740991)15exit_minute = input.int(945, "exit_minute", minval=-9007199254740991, maxval=9007199254740991)16bar_minutes = input.int(5, "bar_minutes", minval=-9007199254740991, maxval=9007199254740991)17clip = input.int(1, "clip", minval=-9007199254740991, maxval=9007199254740991)18 19_q_safe_int(x) =>20 if math.abs(x) > 900719925474099121 runtime.error("an integer left the exact chart range; this run cannot be compared faithfully")22 int(x)23_q_int(x) => _q_safe_int(x < 0 ? math.ceil(x) : math.floor(x))24_q_iadd(a, b) => _q_safe_int(a + b)25_q_isub(a, b) => _q_safe_int(a - b)26_q_imul(a, b) =>27 if a != 0 and math.abs(b) > 9007199254740991 / math.abs(a)28 runtime.error("an integer multiplication left the exact chart range; this run cannot be compared faithfully")29 _q_safe_int(a * b)30_q_ifloordiv(a, b) =>31 _q_r = a % b32 _q_q = (a - _q_r) / b33 _q_safe_int(_q_r != 0 and ((_q_r < 0) != (b < 0)) ? _q_q - 1 : _q_q)34_q_imod(a, b) => _q_safe_int(a - b * _q_ifloordiv(a, b))35 36_q_close = _q_int(math.round(close * 1000000000.0))37 38var float mid = 0.039var int bar_key = 040var int bar_minute = 041var float bar_close = 0.042// clock: completed chart bar's opening timestamp (America/New_York).43_q_clock_prev_minute = hour(time, "America/New_York") * 60 + minute(time, "America/New_York")44_q_clock_prev_second = _q_clock_prev_minute * 60 + second(time, "America/New_York")45_q_clock_prev_weekday = (dayofweek(time, "America/New_York") + 5) % 746_q_clock_prev_day = int(timestamp("UTC", year(time, "America/New_York"), month(time, "America/New_York"), dayofmonth(time, "America/New_York"), 0, 0) / 86400000)47// Current clock: this chart bar's scheduled close, known without a future bar.48// A native next event after a data gap can carry a later time.49_q_clock_minute = hour(time_close, "America/New_York") * 60 + minute(time_close, "America/New_York")50_q_clock_second = _q_clock_minute * 60 + second(time_close, "America/New_York")51_q_clock_weekday = (dayofweek(time_close, "America/New_York") + 5) % 752_q_clock_day = int(timestamp("UTC", year(time_close, "America/New_York"), month(time_close, "America/New_York"), dayofmonth(time_close, "America/New_York"), 0, 0) / 86400000)53_q_clock_seen = 154var _q_closes_buf = array.new_float(20, 0.0)55var int _q_closes_idx = 056var int _q_closes_count = 057var float _q_closes_off = 0.058var float _q_closes_sum = 0.059var float _q_closes_sumsq = 0.060var int _q_closes_skipped = 061int minute_l = na62int second_l = na63int day = na64float close_l = na65int key = na66float width = na67int ends = na68bool in_day = false69bool late = false70 71minute_l := _q_int(_q_clock_prev_minute)72second_l := _q_int(_q_clock_prev_second)73day := _q_int(_q_clock_prev_day)74close_l := _q_close * 1.075key := _q_int(_q_ifloordiv(_q_iadd(_q_imul(day, 1440), minute_l), 5))76if key != bar_key77 if bar_key != 078 _q_sample1 = bar_close79 if na(_q_sample1) or math.abs(_q_sample1) > 1.7976931348623157e30880 _q_closes_skipped := _q_closes_skipped + 181 else82 if _q_closes_count == 083 _q_closes_off := _q_sample184 if _q_closes_count >= 2085 _q_old2 = array.get(_q_closes_buf, _q_closes_idx) - _q_closes_off86 _q_closes_sum := _q_closes_sum - _q_old287 _q_closes_sumsq := _q_closes_sumsq - _q_old2 * _q_old288 else89 _q_closes_count := _q_closes_count + 190 _q_dev2 = _q_sample1 - _q_closes_off91 array.set(_q_closes_buf, _q_closes_idx, _q_sample1)92 _q_closes_sum := _q_closes_sum + _q_dev293 _q_closes_sumsq := _q_closes_sumsq + _q_dev2 * _q_dev294 _q_closes_idx := (_q_closes_idx + 1) % 2095 if _q_closes_idx == 0 and _q_closes_count >= 2096 _q_origin2 = _q_closes_off + _q_closes_sum / _q_closes_count97 _q_total2 = 0.098 _q_totalsq2 = 0.099 for _q_j2 = 0 to 19100 _q_e2 = array.get(_q_closes_buf, _q_j2) - _q_origin2101 _q_total2 := _q_total2 + _q_e2102 _q_totalsq2 := _q_totalsq2 + _q_e2 * _q_e2103 _q_closes_off := _q_origin2104 _q_closes_sum := _q_total2105 _q_closes_sumsq := _q_totalsq2106 if (_q_closes_count >= 20 ? 1 : 0) == 1107 mid := (_q_closes_count == 0 ? 0.0 : _q_closes_off + _q_closes_sum / _q_closes_count)108 width := bands * (_q_closes_count == 0 ? 0.0 : math.sqrt(math.max(_q_closes_sumsq - _q_closes_sum * (_q_closes_sum / _q_closes_count), 0.0) / _q_closes_count))109 ends := _q_int(_q_iadd(bar_minute, bar_minutes))110 in_day := bar_minute >= open_minute and ends < exit_minute111 if in_day and _q_int(strategy.position_size) == 0 and width > 0112 if bar_close > mid + width113 _q_qty3 = _q_int(clip)114 if _q_qty3 <= 0115 runtime.error("market order quantity must be a positive whole unit")116 _q_pos3 = _q_int(strategy.position_size)117 if _q_pos3 < 0 or _q_pos3 > 0 and _q_qty3 < _q_pos3118 runtime.error("this order would add to or partially reduce a position, so its trade ledger would not be faithful")119 strategy.order("q1", strategy.short, _q_qty3)120 else if bar_close < mid - width121 _q_qty4 = _q_int(clip)122 if _q_qty4 <= 0123 runtime.error("market order quantity must be a positive whole unit")124 _q_pos4 = _q_int(strategy.position_size)125 if _q_pos4 > 0 or _q_pos4 < 0 and _q_qty4 < -_q_pos4126 runtime.error("this order would add to or partially reduce a position, so its trade ledger would not be faithful")127 strategy.order("q2", strategy.long, _q_qty4)128 bar_key := _q_int(key)129 bar_minute := _q_int(_q_isub(minute_l, _q_imod(minute_l, 5)))130bar_close := close_l131late := _q_iadd(second_l, 1) >= _q_imul(exit_minute, 60) or minute_l < open_minute132if _q_int(strategy.position_size) < 0133 if close_l <= mid or late134 _q_qty5 = _q_int(math.abs(_q_int(strategy.position_size)))135 if _q_qty5 <= 0136 runtime.error("market order quantity must be a positive whole unit")137 _q_pos5 = _q_int(strategy.position_size)138 if _q_pos5 > 0 or _q_pos5 < 0 and _q_qty5 < -_q_pos5139 runtime.error("this order would add to or partially reduce a position, so its trade ledger would not be faithful")140 strategy.order("q3", strategy.long, _q_qty5)141else if _q_int(strategy.position_size) > 0142 if close_l >= mid or late143 _q_qty6 = _q_int(math.abs(_q_int(strategy.position_size)))144 if _q_qty6 <= 0145 runtime.error("market order quantity must be a positive whole unit")146 _q_pos6 = _q_int(strategy.position_size)147 if _q_pos6 < 0 or _q_pos6 > 0 and _q_qty6 < _q_pos6148 runtime.error("this order would add to or partially reduce a position, so its trade ledger would not be faithful")149 strategy.order("q4", strategy.short, _q_qty6) How it was tested
The published rules, never tuned on the data, with real costs on every fill. Every strategy here is tested the same way.
- Market data
- CME Globex 5-minute bars, Jan 2, 2016 to Jul 31, 2026 RTY from January 2018
- Rules
- As published, with the published parameters, never tuned on this data
- Size
- 1 contract on every trade
- Contract
- The most traded one, rolled as the market moved
- Fees
- The broker's $0.50 a side, plus CME's and the NFA's fees when the window opens
- Slippage
- 1 tick a side on ES, 2 in NQ's regular session and 3 outside it, 1 on other markets, where it was not measured
- Stops and entries
- Tested on 1-second closes and filled at the next bar
- Contracts traded
- ES: 43 contracts, ESH6 to ESU6RTY: 35 contracts, RTYH8 to RTYU6
- Costs paid
- ES: $17,211 in fees, $126,000 in slippageRTY: $25,175 in fees, $70,180 in slippage
- Warm-up
- None: each contract reads only its own bars
- Flagged days
- ES: NoneRTY: None Days the data holds too few bars for. Flagged, not removed.
Could you pass
a prop firm challenge
with the Bollinger band reversion strategy?
A backtest says whether a strategy makes money. Our AI runs its trades through the rules of every prop firm account, then tells you which one it would pass and at what size.
No card needed. Free credits every month.
- Most money: Blue Guardian Futures Direct 50K, $5,084
- Best payout odds: Funded Futures Family Straight to Funded 50K, 98%
- Fastest pass: Phidias Express to Live 50K, 11 days
$5,084
Median net across 2,000 simulated runs
- Evaluation
- None
- First payout
- 97%
- Fees paid
- $1,521
Median net across 2,000 simulated runs
Questions about the Bollinger band reversion strategy
What is the Bollinger band reversion strategy?
Buy a close below the lower Bollinger band, sell a close above the upper one, and exit at the 20-bar mean. The rules follow John Bollinger, Bollinger on Bollinger Bands (2001). Atlantive backtested it on CME futures from January 2016 to July 2026 after costs.
Is the Bollinger band reversion strategy profitable on ES futures?
Not in this backtest: on ES futures from January 2016 to October 2021 it lost $99,536 after costs, over 5,040 trades, positive in 1 of 6 years; on RTY it lost $97,895. Buying and holding one ES contract over the same window made $236,212. The average trade was −$20, its 95% interval −$31 to −$9. These are hypothetical results of a backtest, not of trading.
What are the Bollinger band reversion strategy's rules?
The middle band is the 20-bar mean of the five-minute close and the bands lie 2 standard deviations (population) either side, on every close of the Globex session. A close above the upper band sells short and a close below the lower band buys, on bars that close in the day session before 15:45 New York. The position is closed when a one-second close reaches the middle band, or at 15:45 New York. The rules follow John Bollinger, Bollinger on Bollinger Bands (2001). Its parameters are the published ones, never tuned on the data it was tested on.
How was the Bollinger band reversion strategy backtested?
On CME Globex data from January 2016 to July 2026, one contract, on 5-minute bars, rolled to the most traded contract as the market moved, with the broker's and CME's fees and the slippage measured on each market. Stops and entries were tested on 1-second closes and filled at the next bar. Nothing was fitted to the data.
Can I run the Bollinger band reversion strategy in TradingView?
Yes. The page carries its Pine Script, written by Atlantive's compiler from the same code the backtest ran, for TradingView's strategy tester. A chart's fills and fees can differ from the backtest's, so test it again on the symbol you trade.
Can I change the Bollinger band reversion strategy and test it again?
Yes. Rerun it in Atlantive: a new chat opens with the strategy's rules in the box, for you to read, change and send. The agent writes the code, backtests it on the market and window you name, and reports the result with its costs.