Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Bollinger Band Reversion Strategy

A Pine Script v5 strategy built on BB (close, 20), ATR (14) and Crossover (close, lower). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits use a stop loss and a profit target. Each trade commits 10% of equity and pays 0.05% commission. 4 settings; defaults include Length 20, Standard deviations 2.0 and ATR length 14.

Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.

Does Bollinger Band Reversion Strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 5 of 5 trades.
How did Bollinger Band Reversion Strategy do on BTCUSDT 1D with default settings?
+1.43%
From 26 Jan 2024 to 21 Oct 2026, over 22 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
What alerts does Bollinger Band Reversion Strategy have?
1
Close back inside the lower band.
Does Bollinger Band Reversion Strategy run in Pine Script v6?
Yes
Same 22 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. The v6 script can be downloaded below.
Does Bollinger Band Reversion Strategy use a stop loss?
Yes
strategy.exit sets a stop on line 25.

BTCUSDT · 1D · default settings

  • Basis
  • Upper
  • Lower
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (4)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$10,143$20,253Equity from $10,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots.
Net profit
+1.43%
$143.33
Buy and hold
+102.5%
same period
Closed trades
22
16 won · 6 lost
Profitable
72.7%
of closed trades
Profit factor
1.31
gross profit ÷ gross loss
Max drawdown
2.68%
−$275.38

One run with the author's default settings, $10,000 starting capital, commission as the script sets it. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.

Review

What a careful reader of this script would point out, found by checking the source and the backtest.

Nothing to point out.

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Length20int · min 2basis upper lower
Standard deviations2.0float · min 0.1 · step 0.1basis upper lower
ATR length14int · min 1atr
Stop (ATRs)2.0float · min 0.1 · step 0.1stopLevel

What it calculates

  • BBclose, Length (20), Standard deviations (2.0)basis · line 13
  • BBclose, Length (20), Standard deviations (2.0)upper · line 13
  • BBclose, Length (20), Standard deviations (2.0)lower · line 13
  • ATRATR length (14)atr · line 14
  • Crossoverclose, lowerreEntry · line 16

Signal flow

How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.

closecloseprice datalengthLengthsetting · 20multStandard deviationssetting · 2.0high · low · closehigh · low · closeprice dataatrLenATR lengthsetting · 14stopAtrsStop (ATRs)setting · 2.0basisBB→ basisupperBB→ upperlowerBB→ loweratrATR→ atrreEntryCrossover→ reEntrystopLevelstopLevelvalueentry:LongOpen Longstrategy.entryexit:Exitexit Exitstrategy.exitplot:27Basisplotplot:28Upperplotplot:29Lowerplotfill:BandBandfillalertcondition:32Close back inside the l…alertcondition

Order rules

OrderFires whenBy defaultLine
Open Long longreEntry and strategy.position_size == 0On19
Exit Exit stop and limitstrategy.position_size > 0On25

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Alerts

AlertCallMessageLine
Close back inside the lower bandalertconditionClose crossed back above the lower Bollinger Band32

Does it repaint?

No

No repainting patterns in the source, and the live replay matched history.

5/5trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
  • ClearFuture-bar referencesNo negative history offsets such as close[-1].
  • ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
  • ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.

The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.

Other markets

The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+1.4%+102.5%2273%1.312.7%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+0.6%+5.5%3077%1.310.9%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−4.6%+9.8%2255%0.516.3%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.8%+8.4%2763%0.762.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−5.1%+16.7%2255%0.617.2%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−1.2%+21.5%2763%0.672.1%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+2.3%+148.3%2167%1.421.9%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.2%+17.1%2471%0.891.2%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market683%$28.25
Sideways market967%$84.41
Falling market771%$30.67

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

3.4%

The 95th percentile of the worst drawdown when the same 22 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 1.3% to 3.4%; the tick is what actually happened, 2.3%. Order luck alone moves it this much.

0%4%
All 22 trades
SideEntryExitBarsP&L
long15 Apr 2024 65,661.9022 Apr 2024 66,487.907$11.57
long4 May 2024 62,882.005 May 2024 63,892.001$15.06
long16 Jun 2024 66,228.3024 Jun 2024 62,716.608−$54.11
long26 Jun 2024 61,806.004 Jul 2024 56,815.908−$81.43
long7 Jul 2024 58,230.1013 Jul 2024 59,639.906$22.93
long8 Aug 2024 55,133.8018 Aug 2024 60,258.6010$91.07
long8 Sep 2024 54,160.9013 Sep 2024 58,416.605$77.54
long7 Feb 2025 96,554.4020 Feb 2025 97,470.5013$8.55
long2 Mar 2025 86,064.603 Mar 2025 94,270.001$95.11
long10 Apr 2025 82,615.2011 Apr 2025 83,271.101$7.06
long7 Jun 2025 104,288.009 Jun 2025 106,563.002$21.19
long4 Aug 2025 114,209.007 Aug 2025 116,813.003$22.25
long27 Aug 2025 111,763.005 Sep 2025 112,529.009$5.99
long27 Sep 2025 109,643.0029 Sep 2025 113,940.002$39.08
long6 Nov 2025 103,885.0016 Nov 2025 93,188.7010−$106.79
long23 Nov 2025 84,739.802 Dec 2025 91,084.609$75.09
long17 Dec 2025 87,863.4022 Dec 2025 89,674.105$20.08
long3 Feb 2026 78,738.605 Feb 2026 68,801.102−$130.52
long7 Feb 2026 70,580.3025 Feb 2026 67,758.4018−$41.51
long24 May 2026 76,752.0028 May 2026 72,996.804−$50.37
long8 Jun 2026 63,332.0015 Jun 2026 67,011.307$57.31
long27 Jun 2026 60,097.303 Jul 2026 62,431.406$38.20

Similar scripts

Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.

ScriptSharesTypeNetTradesMax drawdown
Bollinger Band Reversion Strategy this page—v5 strategy+1.4%222.7%
TrendMaAlignmentStrategy - Long term trades by Trendoscopeatr bbv4 strategy−22.0%846.3%
BuyTheDip by Trendoscopeatr bbv4 strategy+4.6%28.3%
Breakout Trend Trading Strategy - V2 by Trendoscopeatr bbv4 strategy−1.2%19.8%

Upgrade and export

Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.

  • No v6-only features. v6 is not needed to run this script.

Clean v5

Verified

Nothing to change.

Does it run in Pine Script v6?

Yes

Same 22 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.

Download the v6 script

⋯// © Zeal Terminal-//@version=5+//@version=6strategy("Bollinger Band Reversion Strategy", shorttitle = "BB Reversion", overlay = true, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, commission_type = strategy.commission.percent, commission_value = 0.05, slippage = 1)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 12 msYes 1,000 bars in 29 msNot measured
PineTSNot testedNot testedNot measured

“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.

Source

Written by Zeal Terminal and published under the Mozilla Public License 2.0.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © Zeal Terminal//@version=5strategy("Bollinger Band Reversion Strategy", shorttitle = "BB Reversion", overlay = true, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, commission_type = strategy.commission.percent, commission_value = 0.05, slippage = 1) // Not investment advice. Buys a close back inside the lower band and takes// profit at the basis, with a stop a fixed number of ATRs below entry.length   = input.int(20, "Length", minval = 2)mult     = input.float(2.0, "Standard deviations", minval = 0.1, step = 0.1)atrLen   = input.int(14, "ATR length", minval = 1)stopAtrs = input.float(2.0, "Stop (ATRs)", minval = 0.1, step = 0.1) [basis, upper, lower] = ta.bb(close, length, mult)atr = ta.atr(atrLen) reEntry = ta.crossover(close, lower) if reEntry and strategy.position_size == 0    strategy.entry("Long", strategy.long) var float stopLevel = naif strategy.position_size > 0 and strategy.position_size[1] == 0    stopLevel := close - stopAtrs * atrif strategy.position_size > 0    strategy.exit("Exit", "Long", stop = stopLevel, limit = basis) plot(basis, "Basis", color = #ffb74d)u = plot(upper, "Upper", color = color.new(#42a5f5, 40))l = plot(lower, "Lower", color = color.new(#42a5f5, 40))fill(u, l, color = color.new(#42a5f5, 94), title = "Band") alertcondition(reEntry, "Close back inside the lower band", "Close crossed back above the lower Bollinger Band")