Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (9)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$6,477$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
−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.

SettingDefaultType and rangeFeeds
Long (no label in the script)trueboolentry Long exit Exit line 33 line 37
Short (no label in the script)trueboolentry Short exit Exit line 35 line 39
Length (no label in the script)20int · min 1basis dev
Mult (no label in the script)2.0float · min 0.001 · max 50dev
Source (no label in the script)closesourcebasis dev
Show Bollinger BandstrueboolcolorBasis colorUpper colorLower colorBands
Show Offsettruebooloffset
Start Timetimestamp("01 Jan 2000 00:00 +0000")timetruetime
Final Timetimestamp("31 Dec 2099 23:59 +0000")timetruetime 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.

closecloseprice datalengthLengthsetting · 20multMultsetting · 2.0timetimeprice datastartTimeStart Timesetting · timestamp("01 Jan 2…finalTimeFinal Timesetting · timestamp("31 Dec 2…basisSMA→ basisdevStdev→ devupper, lowerupper · lower2 valuesoffsetoffsetvaluetruetimetruetimeconditioncolorBasis, colorUpper, colorLower, colorBandsColourcolorBasis · colorUpper +2entry:LongOpen Longstrategy.entryentry:ShortOpen Shortstrategy.entryexit:Exitexit Exitstrategy.exitclose_all:close_all strategy.close_allplot:26Basisplotplot:27Upperplotplot:28Lowerplotfill:BackgroundBackgroundfill

Order rules

OrderFires whenBy defaultLine
Open Long longtruetimetime > startTime and time < finalTimeOn “Long”34
Open Short shorttruetimetime > startTime and time < finalTimeOn “Short”36
Exit Exit stoplong == falseOn38
Exit Exit stopshort == falseOn40
Close time > finalTimeOn42

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.

11/11trades 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−32.0%+102.5%4129%0.8161.5%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−22.5%+5.5%4423%0.6836.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+127.8%+9.8%3543%1.4135.1%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+11.4%+8.4%4129%1.1329.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−72.7%+16.7%4134%0.6886.4%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+2.0%+21.5%3631%1.0231.1%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−32.9%+148.3%3529%0.8081.2%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−6.5%+17.1%3837%0.8628.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 barsTradesWonP&L
Rising market1331%−$1,050.32
Sideways market1729%−$744.07
Falling market1127%−$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.

0%80%
All 41 trades
SideEntryExitBarsP&L
long15 Feb 2024 51,795.2012 Apr 2024 65,102.5057$2,544.11
short12 Apr 2024 65,102.5015 May 2024 65,548.2033−$119.42
long15 May 2024 65,548.2011 Jun 2024 66,946.2027$255.76
short11 Jun 2024 66,946.2015 Jul 2024 63,846.0034$585.69
long15 Jul 2024 63,846.003 Aug 2024 61,498.3019−$537.10
short3 Aug 2024 61,498.3023 Aug 2024 62,924.8020−$321.03
long23 Aug 2024 62,924.804 Sep 2024 55,725.7012−$1,504.34
short4 Sep 2024 55,725.7018 Sep 2024 61,532.6014−$1,197.68
long18 Sep 2024 61,532.6010 Oct 2024 59,763.7022−$305.80
short10 Oct 2024 59,763.7014 Oct 2024 66,273.304−$1,059.41
long14 Oct 2024 66,273.3020 Dec 2024 93,501.4067$3,629.28
short20 Dec 2024 93,501.407 Jan 2025 102,236.0018−$1,193.93
long7 Jan 2025 102,236.009 Jan 2025 91,886.202−$1,111.63
short9 Jan 2025 91,886.2015 Jan 2025 100,187.006−$924.23
long15 Jan 2025 100,187.002 Feb 2025 96,675.6018−$338.22
short2 Feb 2025 96,675.602 Apr 2025 88,251.2059$746.88
long2 Apr 2025 88,251.206 Apr 2025 81,046.004−$787.81
short6 Apr 2025 81,046.0021 Apr 2025 87,898.6015−$747.44
long21 Apr 2025 87,898.605 Jun 2025 102,184.0045$1,267.56
short5 Jun 2025 102,184.002 Jul 2025 109,117.0027−$636.78
long2 Jul 2025 109,117.0030 Jul 2025 116,306.0028$545.77
short30 Jul 2025 116,306.0011 Aug 2025 120,966.0012−$375.53
long11 Aug 2025 120,966.0024 Aug 2025 111,785.0013−$664.86
short24 Aug 2025 111,785.0012 Sep 2025 115,483.0019−$281.14
long12 Sep 2025 115,483.0025 Sep 2025 109,801.0013−$382.08
short25 Sep 2025 109,801.002 Oct 2025 119,421.007−$656.04
long2 Oct 2025 119,421.0010 Oct 2025 106,539.008−$712.05
short10 Oct 2025 106,539.009 Dec 2025 94,116.1060$750.21
long9 Dec 2025 94,116.1015 Dec 2025 87,030.906−$515.86
short15 Dec 2025 87,030.902 Jan 2026 89,801.5018−$204.35
long2 Jan 2026 89,801.5021 Jan 2026 87,623.1019−$152.56
short21 Jan 2026 87,623.104 Mar 2026 70,277.1042$1,107.93
long4 Mar 2026 70,277.1027 Mar 2026 66,164.6023−$412.74
short27 Mar 2026 66,164.607 Apr 2026 71,940.6011−$585.38
long7 Apr 2026 71,940.6022 May 2026 76,212.7045$344.66
short22 May 2026 76,212.7021 Jul 2026 66,018.6060$813.50
long21 Jul 2026 66,018.6031 Jul 2026 62,682.0010−$363.44
short31 Jul 2026 62,682.0019 Aug 2026 65,405.2019−$305.69
long19 Aug 2026 65,405.2010 Sep 2026 76,527.4022$1,052.35
short10 Sep 2026 76,527.4018 Sep 2026 80,890.308−$438.13
long18 Sep 2026 80,890.308 Oct 2026 80,996.8020−$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.

ScriptSharesTypeNetTradesMax drawdown
Bollinger Stop Strategy this page—v5 strategy−32.0%4161.5%
Double Bollinger Binary Options by Trade_by_DBsma stdevv5 strategyNo trades on this market
Improved Bollinger Swing Strategy Stock Nasdaq by exlux99sma stdevv4 strategy−20.4%722.3%
I11L Long Put-Call Ratio Inversion by I11Lsma stdevv5 strategyNo trades on this market
P-Signal Strategy by Kharevskystdev smav4 strategy−9.7%2934.6%
P-Signal Strategy & Alert by Kharevskystdev smav4 strategy−9.7%2934.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.

Clean v5

VerifiedDownload the v5 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

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 14 msYes 1,000 bars in 41 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

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()