Pine Script v5 · Strategy
Bollinger Stop Strategy
A Pine Script v5 strategy built on SMA (close, 20) and Stdev (close, 20). It has 5 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade commits 100% of equity and pays 0.1 commission. 9 settings; defaults include Length 20, Mult 2.0 and Source close.
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 Stop Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 11 of 11 trades.
- How did Bollinger Stop Strategy do on BTCUSDT 1D with default settings?
- −32.03%
- From 26 Jan 2024 to 21 Oct 2026, over 41 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Bollinger Stop Strategy run in Pine Script v6?
- No
- The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L29:C55: 'fill' has no 'transp' parameter in Pine Script v6. Use color.new(color, transparency) instead. The v6 version is shown for reference and is not offered as a download.
- Does Bollinger Stop Strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 38, 40.
- Does Bollinger Stop Strategy run in Zeal Terminal?
- Yes
- It compiles in 14 ms and runs 1,000 bars in 41 ms, in the browser.
BTCUSDT · 1D · default settings
- Basis
- Upper
- Lower
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −32.03%
- −$3,202.95
- Buy and hold
- +102.5%
- same period
- Closed trades
- 41
- 12 won · 29 lost
- Profitable
- 29.3%
- of closed trades
- Profit factor
- 0.81
- gross profit ÷ gross loss
- Max drawdown
- 61.51%
- −$8,159.38
One run with the author's default settings, $10,000 starting capital, commission as the script sets it. A short position was still open at the last bar. 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.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
5 settings have no label
In the settings dialog long (line 6), short (line 7), length (line 8), mult (line 9), source (line 10) show an empty name. The labels on this page come from the variable names.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses an argument v6 removed
when = on line 34, 36. The upgraded version below moves each call inside an if block.
Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Long (no label in the script) | true | bool | entry Long exit Exit line 33 line 37 |
| Short (no label in the script) | true | bool | entry Short exit Exit line 35 line 39 |
| Length (no label in the script) | 20 | int · min 1 | basis dev |
| Mult (no label in the script) | 2.0 | float · min 0.001 · max 50 | dev |
| Source (no label in the script) | close | source | basis dev |
| Show Bollinger Bands | true | bool | colorBasis colorUpper colorLower colorBands |
| Show Offset | true | bool | offset |
| Start Time | timestamp("01 Jan 2000 00:00 +0000") | time | truetime |
| Final Time | timestamp("31 Dec 2099 23:59 +0000") | time | truetime close_all line 41 |
What it calculates
- SMASource (close), Length (20)
basis · line 16 - StdevSource (close), Length (20)
dev · line 17
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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | truetimetime > startTime and time < finalTime | On “Long” | 34 |
| Open Short short | truetimetime > startTime and time < finalTime | On “Short” | 36 |
| Exit Exit stop | long == false | On | 38 |
| Exit Exit stop | short == false | On | 40 |
| Close | time > finalTime | On | 42 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
No
No repainting patterns in the source, and the live replay matched history.
- 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | −32.0% | +102.5% | 41 | 29% | 0.81 | 61.5% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −22.5% | +5.5% | 44 | 23% | 0.68 | 36.4% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +127.8% | +9.8% | 35 | 43% | 1.41 | 35.1% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +11.4% | +8.4% | 41 | 29% | 1.13 | 29.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −72.7% | +16.7% | 41 | 34% | 0.68 | 86.4% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +2.0% | +21.5% | 36 | 31% | 1.02 | 31.1% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −32.9% | +148.3% | 35 | 29% | 0.80 | 81.2% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −6.5% | +17.1% | 38 | 37% | 0.86 | 28.0% | 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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 13 | 31% | −$1,050.32 |
| Sideways market | 17 | 29% | −$744.07 |
| Falling market | 11 | 27% | −$1,401.55 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
69.6%
The 95th percentile of the worst drawdown when the same 41 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 42.6% to 69.6%; the tick is what actually happened, 57.8%. Order luck alone moves it this much.
All 41 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 15 Feb 2024 51,795.20 | 12 Apr 2024 65,102.50 | 57 | $2,544.11 |
| short | 12 Apr 2024 65,102.50 | 15 May 2024 65,548.20 | 33 | −$119.42 |
| long | 15 May 2024 65,548.20 | 11 Jun 2024 66,946.20 | 27 | $255.76 |
| short | 11 Jun 2024 66,946.20 | 15 Jul 2024 63,846.00 | 34 | $585.69 |
| long | 15 Jul 2024 63,846.00 | 3 Aug 2024 61,498.30 | 19 | −$537.10 |
| short | 3 Aug 2024 61,498.30 | 23 Aug 2024 62,924.80 | 20 | −$321.03 |
| long | 23 Aug 2024 62,924.80 | 4 Sep 2024 55,725.70 | 12 | −$1,504.34 |
| short | 4 Sep 2024 55,725.70 | 18 Sep 2024 61,532.60 | 14 | −$1,197.68 |
| long | 18 Sep 2024 61,532.60 | 10 Oct 2024 59,763.70 | 22 | −$305.80 |
| short | 10 Oct 2024 59,763.70 | 14 Oct 2024 66,273.30 | 4 | −$1,059.41 |
| long | 14 Oct 2024 66,273.30 | 20 Dec 2024 93,501.40 | 67 | $3,629.28 |
| short | 20 Dec 2024 93,501.40 | 7 Jan 2025 102,236.00 | 18 | −$1,193.93 |
| long | 7 Jan 2025 102,236.00 | 9 Jan 2025 91,886.20 | 2 | −$1,111.63 |
| short | 9 Jan 2025 91,886.20 | 15 Jan 2025 100,187.00 | 6 | −$924.23 |
| long | 15 Jan 2025 100,187.00 | 2 Feb 2025 96,675.60 | 18 | −$338.22 |
| short | 2 Feb 2025 96,675.60 | 2 Apr 2025 88,251.20 | 59 | $746.88 |
| long | 2 Apr 2025 88,251.20 | 6 Apr 2025 81,046.00 | 4 | −$787.81 |
| short | 6 Apr 2025 81,046.00 | 21 Apr 2025 87,898.60 | 15 | −$747.44 |
| long | 21 Apr 2025 87,898.60 | 5 Jun 2025 102,184.00 | 45 | $1,267.56 |
| short | 5 Jun 2025 102,184.00 | 2 Jul 2025 109,117.00 | 27 | −$636.78 |
| long | 2 Jul 2025 109,117.00 | 30 Jul 2025 116,306.00 | 28 | $545.77 |
| short | 30 Jul 2025 116,306.00 | 11 Aug 2025 120,966.00 | 12 | −$375.53 |
| long | 11 Aug 2025 120,966.00 | 24 Aug 2025 111,785.00 | 13 | −$664.86 |
| short | 24 Aug 2025 111,785.00 | 12 Sep 2025 115,483.00 | 19 | −$281.14 |
| long | 12 Sep 2025 115,483.00 | 25 Sep 2025 109,801.00 | 13 | −$382.08 |
| short | 25 Sep 2025 109,801.00 | 2 Oct 2025 119,421.00 | 7 | −$656.04 |
| long | 2 Oct 2025 119,421.00 | 10 Oct 2025 106,539.00 | 8 | −$712.05 |
| short | 10 Oct 2025 106,539.00 | 9 Dec 2025 94,116.10 | 60 | $750.21 |
| long | 9 Dec 2025 94,116.10 | 15 Dec 2025 87,030.90 | 6 | −$515.86 |
| short | 15 Dec 2025 87,030.90 | 2 Jan 2026 89,801.50 | 18 | −$204.35 |
| long | 2 Jan 2026 89,801.50 | 21 Jan 2026 87,623.10 | 19 | −$152.56 |
| short | 21 Jan 2026 87,623.10 | 4 Mar 2026 70,277.10 | 42 | $1,107.93 |
| long | 4 Mar 2026 70,277.10 | 27 Mar 2026 66,164.60 | 23 | −$412.74 |
| short | 27 Mar 2026 66,164.60 | 7 Apr 2026 71,940.60 | 11 | −$585.38 |
| long | 7 Apr 2026 71,940.60 | 22 May 2026 76,212.70 | 45 | $344.66 |
| short | 22 May 2026 76,212.70 | 21 Jul 2026 66,018.60 | 60 | $813.50 |
| long | 21 Jul 2026 66,018.60 | 31 Jul 2026 62,682.00 | 10 | −$363.44 |
| short | 31 Jul 2026 62,682.00 | 19 Aug 2026 65,405.20 | 19 | −$305.69 |
| long | 19 Aug 2026 65,405.20 | 10 Sep 2026 76,527.40 | 22 | $1,052.35 |
| short | 10 Sep 2026 76,527.40 | 18 Sep 2026 80,890.30 | 8 | −$438.13 |
| long | 18 Sep 2026 80,890.30 | 8 Oct 2026 80,996.80 | 20 | −$4.96 |
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Bollinger Stop Strategy this page | — | v5 strategy | −32.0% | 41 | 61.5% |
| Double Bollinger Binary Options by Trade_by_DB | sma stdev | v5 strategy | No trades on this market | ||
| Improved Bollinger Swing Strategy Stock Nasdaq by exlux99 | sma stdev | v4 strategy | −20.4% | 7 | 22.3% |
| I11L Long Put-Call Ratio Inversion by I11L | sma stdev | v5 strategy | No trades on this market | ||
| P-Signal Strategy by Kharevsky | stdev sma | v4 strategy | −9.7% | 29 | 34.6% |
| P-Signal Strategy & Alert by Kharevsky | stdev sma | v4 strategy | −9.7% | 29 | 34.6% |
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.
- 2 strategy calls use the when = argument (line 34, 36). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- 5 settings use the untyped input() (line 6, 7, 10, 11, 12). It still compiles in v6; input.int, input.float or input.source state the type.
- No v6-only features. v6 is not needed to run this script.
Same 41 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 6: input() → input.bool()
- Line 7: input() → input.bool()
- Line 10: input() → input.source()
- Line 11: input() → input.bool()
- Line 12: input() → input.bool()
- Line 34: when = truetime → if block
- Line 36: when = truetime → if block
⋯//Settings-long = input(true)+long = input.bool(true)-short = input(true)+short = input.bool(true)length = input.int(20, minval=1)mult = input.float(2.0, minval=0.001, maxval=50)-source = input(close)+source = input.source(close)-showbb = input(true, title = "Show Bollinger Bands")+showbb = input.bool(true, title = "Show Bollinger Bands")-showof = input(true, title = "Show Offset")+showof = input.bool(true, title = "Show Offset")startTime = input.time(defval = timestamp("01 Jan 2000 00:00 +0000"), title = "Start Time", inline = "time1")⋯ if long- strategy.entry("Long", strategy.long, stop = upper, when = truetime)+ if truetime+ strategy.entry("Long", strategy.long, stop = upper) if short- strategy.entry("Short", strategy.short, stop = lower, when = truetime)+ if truetime+ strategy.entry("Short", strategy.short, stop = lower) if long == false⋯Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L29:C55: 'fill' has no 'transp' parameter in Pine Script v6. Use color.new(color, transparency) instead. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © ROBO_Trading-//@version=5+//@version=6strategy(title = "Bollinger Stop Strategy", shorttitle = "BBStop", overlay = true, default_qty_type = strategy.percent_of_equity, initial_capital = 10000, default_qty_value = 100, commission_value = 0.1)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 14 ms | Yes 1,000 bars in 41 ms | Not measured |
| PineTS | Not tested | Not tested | Not 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
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © ROBO_Trading//@version=5strategy(title = "Bollinger Stop Strategy", shorttitle = "BBStop", overlay = true, default_qty_type = strategy.percent_of_equity, initial_capital = 10000, default_qty_value = 100, commission_value = 0.1)//Settingslong = input(true)short = input(true)length = input.int(20, minval=1)mult = input.float(2.0, minval=0.001, maxval=50)source = input(close)showbb = input(true, title = "Show Bollinger Bands")showof = input(true, title = "Show Offset")startTime = input.time(defval = timestamp("01 Jan 2000 00:00 +0000"), title = "Start Time", inline = "time1")finalTime = input.time(defval = timestamp("31 Dec 2099 23:59 +0000"), title = "Final Time", inline = "time1")//Bollinger Bandsbasis = ta.sma(source, length)dev = mult * ta.stdev(source, length)upper = basis + devlower = basis - dev//Show indicatoroffset = showof ? 1 : 0colorBasis = showbb ? color.gray : nacolorUpper = showbb ? color.blue : nacolorLower = showbb ? color.blue : nacolorBands = showbb ? color.blue : nap0 = plot(basis, "Basis", color = colorBasis, offset = offset)p1 = plot(upper, "Upper", color = colorUpper, offset = offset)p2 = plot(lower, "Lower", color = colorLower, offset = offset)fill(p1, p2, title = "Background", color = colorBands, transp = 90)//Tradingtruetime = time > startTime and time < finalTimeif basis > 0 and truetime if long strategy.entry("Long", strategy.long, stop = upper, when = truetime) if short strategy.entry("Short", strategy.short, stop = lower, when = truetime) if long == false strategy.exit("Exit", "Short", stop = upper) if short == false strategy.exit("Exit", "Long", stop = lower)if time > finalTime strategy.close_all()