Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Improved Bollinger Swing Strategy Stock Nasdaq

A Pine Script v4 strategy built on SMA (source, 25), Stdev (source, 25) and Crossover (source, lower). It has 6 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 100% of equity and pays 0.01% commission. 12 settings; defaults include Length BB long 25, MULT BB long 2.9 and Length BB short 36.

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 Improved Bollinger Swing Strategy Stock Nasdaq repaint?
Yes
At least one pattern in the source can repaint: intrabar recalculation.
How did Improved Bollinger Swing Strategy Stock Nasdaq do on BTCUSDT 1D with default settings?
−20.43%
From 26 Jan 2024 to 21 Oct 2026, over 7 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Improved Bollinger Swing Strategy Stock Nasdaq be converted to Pine Script v5?
No
The automatic step from v4 to v5 changes the results, so no v5 download is offered; the edits are shown below.
Does Improved Bollinger Swing Strategy Stock Nasdaq use a stop loss?
Yes
strategy.exit sets a stop on line 29, 33.
Does Improved Bollinger Swing Strategy Stock Nasdaq run in Zeal Terminal?
Yes
It compiles in 12 ms and runs 1,000 bars in 38 ms, in the browser.

BTCUSDT · 1D · default settings

  • SMA
  • Stdev
  • Stdev
  • Crossover
  • Crossunder
  • 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 (12)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$79,569$202,527Equity from $100,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. The script plots nothing itself; the lines and the lower pane are its own calculations, drawn for reference. Zeal Terminal's engine currently reads an order side written as 1, 0 as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 28, 32) so the engine trades the way the script says.
Net profit
−20.43%
−$20,431.10
Buy and hold
+102.5%
same period
Closed trades
7
1 won · 6 lost
Profitable
14.3%
of closed trades
Profit factor
0.11
gross profit ÷ gross loss
Max drawdown
22.30%
−$22,831.90

One run with the author's default settings, $100,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.

  • Check

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • Note

    4 settings have no label

    In the settings dialog longEntry (line 17), shortEntry (line 18), risk (line 20), leverage (line 21) 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 28, 30, 32, 34. The upgraded version below moves each call inside an if block.

Upgrade and export

Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.

  • Upgrading to v5 renames sma → ta.sma, stdev → ta.stdev, crossover → ta.crossover, crossunder → ta.crossunder, round → math.round, pow → math.pow.
  • 4 strategy calls use the when = argument (line 28, 30, 32, 34). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Differs

Trades differ: 7 before, 7 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 3: //@version=4 → //@version=5
  • Line 10: sma → ta.sma
  • Line 11: stdev → ta.stdev
  • Line 12: stdev → ta.stdev
  • Line 15: crossover → ta.crossover
  • Line 16: crossunder → ta.crossunder
5 more edits
  • Line 19: round → math.round
  • Line 19: pow → math.pow
  • Line 19: pow → math.pow
  • Line 28: strategy.entry(…, 1) → strategy.entry(…, strategy.long)
  • Line 32: strategy.entry(…, 0) → strategy.entry(…, strategy.short)
⋯// © exlux99-//@version=4+//@version=5strategy("BB NDX strategy", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, calc_on_every_tick = true, commission_type = strategy.commission.percent, commission_value = 0.01)⋯mult2 = input(3.2, minval=0.001, maxval=50, step=0.1, title="MULT BB short")-basis = sma(source, length)+basis = ta.sma(source, length)-dev = mult * stdev(source, length)+dev = mult * ta.stdev(source, length)-dev2 = mult2 * stdev(source, length2)+dev2 = mult2 * ta.stdev(source, length2)upper = basis + dev2lower = basis - dev-buyEntry = crossover(source, lower)+buyEntry = ta.crossover(source, lower)-sellEntry = crossunder(source, upper)+sellEntry = ta.crossunder(source, upper)longEntry=input(true)shortEntry=input(true)-g(v, p) => round(v * (pow(10, p))) / pow(10, p)+g(v, p) => math.round(v * (math.pow(10, p))) / math.pow(10, p)risk     = input(100)⋯if(longEntry)-    strategy.entry("long",1,c,when=buyEntry)+    strategy.entry("long",strategy.long,c,when=buyEntry)    strategy.exit("short_tp/sl", "long", profit=close * tplong / syminfo.mintick, loss=close * sllong / syminfo.mintick, comment='LONG EXIT',  alert_message = 'closeshort')⋯if(shortEntry)-    strategy.entry("short",0,c,when=sellEntry)+    strategy.entry("short",strategy.short,c,when=sellEntry)    strategy.exit("short_tp/sl", "short", profit=close * tpshort / syminfo.mintick, loss=close * slshort / syminfo.mintick, comment='SHORT EXIT',  alert_message = 'closeshort')⋯

Clean v5

Verified

Same 7 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 6: input() → input.int()
  • Line 7: input() → input.float()
  • Line 8: input() → input.int()
  • Line 9: input() → input.float()
  • Line 17: input() → input.bool()
  • Line 18: input() → input.bool()
10 more edits
  • Line 20: input() → input.int()
  • Line 21: input() → input.float()
  • Line 23: input() → input.float()
  • Line 24: input() → input.float()
  • Line 25: input() → input.float()
  • Line 26: input() → input.float()
  • Line 28: when = buyEntry → if block
  • Line 30: when = sellEntry → if block
  • Line 32: when = sellEntry → if block
  • Line 34: when = buyEntry → if block
⋯source = close-length = input(25, minval=1, title="Length BB long")+length = input.int(25, minval=1, title="Length BB long")-mult = input(2.9, minval=0.001, maxval=50, step=0.1, title="MULT BB long")+mult = input.float(2.9, minval=0.001, maxval=50, step=0.1, title="MULT BB long")-length2 = input(36, minval=1, title="Length BB short")+length2 = input.int(36, minval=1, title="Length BB short")-mult2 = input(3.2, minval=0.001, maxval=50, step=0.1, title="MULT BB short")+mult2 = input.float(3.2, minval=0.001, maxval=50, step=0.1, title="MULT BB short")basis = ta.sma(source, length)⋯sellEntry = ta.crossunder(source, upper)-longEntry=input(true)+longEntry=input.bool(true)-shortEntry=input(true)+shortEntry=input.bool(true)g(v, p) => math.round(v * (math.pow(10, p))) / math.pow(10, p)-risk     = input(100)+risk     = input.int(100)-leverage = input(1.0, step = 0.5)+leverage = input.float(1.0, step = 0.5)c = g((strategy.equity * leverage / open) * (risk / 100), 4)-tplong=input(0.065, step=0.005, title="Take profit % for long")+tplong=input.float(0.065, step=0.005, title="Take profit % for long")-sllong=input(0.04, step=0.005, title="Stop loss % for long")+sllong=input.float(0.04, step=0.005, title="Stop loss % for long")-tpshort=input(0.025, step=0.005, title="Take profit % for short")+tpshort=input.float(0.025, step=0.005, title="Take profit % for short")-slshort=input(0.04, step=0.005, title="Stop loss % for short")+slshort=input.float(0.04, step=0.005, title="Stop loss % for short")if(longEntry)-    strategy.entry("long",strategy.long,c,when=buyEntry)+    if buyEntry+        strategy.entry("long",strategy.long,c)    strategy.exit("short_tp/sl", "long", profit=close * tplong / syminfo.mintick, loss=close * sllong / syminfo.mintick, comment='LONG EXIT',  alert_message = 'closeshort')-    strategy.close("long",when=sellEntry)+    if sellEntry+        strategy.close("long")if(shortEntry)-    strategy.entry("short",strategy.short,c,when=sellEntry)+    if sellEntry+        strategy.entry("short",strategy.short,c)    strategy.exit("short_tp/sl", "short", profit=close * tpshort / syminfo.mintick, loss=close * slshort / syminfo.mintick, comment='SHORT EXIT',  alert_message = 'closeshort')-    strategy.close("short",when=buyEntry)+    if buyEntry+        strategy.close("short")

Does it run in Pine Script v6?

No

The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 7 before, 3 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © exlux99-//@version=5+//@version=6strategy("BB NDX strategy", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, calc_on_every_tick = true, commission_type = strategy.commission.percent, commission_value = 0.01)⋯

Settings

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

SettingDefaultType and rangeFeeds
Length BB long25int · min 1basis dev
MULT BB long2.9float · min 0.001 · max 50 · step 0.1dev
Length BB short36int · min 1dev2
MULT BB short3.2float · min 0.001 · max 50 · step 0.1dev2
Long Entry (no label in the script)trueboolentry long exit short_tp/sl close long line 27
Short Entry (no label in the script)trueboolentry short exit short_tp/sl close short line 31
Risk (no label in the script)100intc
Leverage (no label in the script)1.0float · step 0.5c
Take profit % for long0.065float · step 0.005exit short_tp/sl
Stop loss % for long0.04float · step 0.005exit short_tp/sl
Take profit % for short0.025float · step 0.005exit short_tp/sl
Stop loss % for short0.04float · step 0.005exit short_tp/sl

What it calculates

  • SMA (sma, ta.sma in v5)source, Length BB long (25)basis · line 10
  • Stdev (stdev, ta.stdev in v5)source, Length BB long (25)dev · line 11
  • Stdev (stdev, ta.stdev in v5)source, Length BB short (36)dev2 · line 12
  • Crossover (crossover, ta.crossover in v5)source, lowerbuyEntry · line 15
  • Crossunder (crossunder, ta.crossunder in v5)source, uppersellEntry · 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.

lengthLength BB longsetting · 25multMULT BB longsetting · 2.9mult2MULT BB shortsetting · 3.2length2Length BB shortsetting · 36closecloseprice dataopenopenprice dataleverageLeveragesetting · 1.0riskRisksetting · 100basisSMA→ basisdevStdev→ devdev2Stdev→ dev2buyEntryCrossover→ buyEntrysellEntryCrossunder→ sellEntrysourcesourcevalueupperuppervaluelowerlowervalueccvalueentry:longOpen longstrategy.entryexit:short_tp/slexit short_tp/slstrategy.exitclose:longClose longstrategy.closeentry:shortOpen shortstrategy.entryclose:shortClose shortstrategy.close

Order rules

OrderFires whenBy defaultLine
Open long longbuyEntryOn28
Exit short_tp/sl stop and limit(longEntry)On29
Close longsellEntryOn30
Open short shortsellEntryOn32
Exit short_tp/sl stop and limit(shortEntry)On33
Close shortbuyEntryOn34

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

Does it repaint?

Yes

At least one pattern in the source can repaint; it is marked Check below.

4/4trades 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. On 3 of them the position changed while the bar was forming before it settled. Anyone watching live sees those changes; once the bar closes it matches history.
  • ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
  • ClearFuture-bar referencesNo negative history offsets such as close[-1].
  • CheckIntrabar recalculationcalc_on_every_tick = true. Live values can differ from history.
  • 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−20.4%+102.5%714%0.1122.3%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−14.2%+5.5%825%0.3617.8%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−24.4%+9.8%1429%0.2930.6%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−11.9%+8.4%1436%0.6517.5%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−19.1%+16.7%50%0.0019.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−17.4%+21.5%922%0.3217.4%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+5.5%+148.3%1060%1.318.3%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−5.1%+17.1%743%0.7018.3%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 market1100%$2,400.75
Sideways market40%−$14,970.10
Falling market20%−$7,861.77

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

How bad could the drawdown be?

22.3%

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

0%26%
All 7 trades
SideEntryExitBarsP&L
short22 May 2024 70,148.3023 May 2024 68,419.201$2,400.75
long28 Feb 2025 84,708.6028 Feb 2025 81,320.200−$4,138.38
short24 Apr 2025 93,691.102 May 2025 97,550.708−$4,078.87
long2 Feb 2026 76,968.203 Feb 2026 73,818.701−$3,785.21
long7 Feb 2026 70,580.307 Feb 2026 67,757.000−$4,076.56
long4 Jun 2026 64,142.804 Jun 2026 61,577.000−$3,333.72
short24 Aug 2026 77,734.0025 Aug 2026 80,893.701−$3,419.14

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
Improved Bollinger Swing Strategy Stock Nasdaq this page—v4 strategy−20.4%722.3%
Double Bollinger Binary Options by Trade_by_DBsma stdevv5 strategyNo trades on this market
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%
Bollinger Stop Strategy by ROBO_Tradingsma stdevv5 strategy−32.0%4161.5%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 12 msWith a workaround 1,000 bars in 38 msNot measured
PineTSNo v5 and v6 only—Not measured

Zeal Terminal's engine currently reads an order side written as 1, 0 as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 28, 32) so the engine trades the way the script says.

“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. PineTS runs Pine Script v5 and v6 only.

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/// © exlux99//@version=4strategy("BB NDX strategy", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, calc_on_every_tick = true, commission_type = strategy.commission.percent, commission_value = 0.01)source = closelength = input(25, minval=1, title="Length BB long")mult = input(2.9, minval=0.001, maxval=50, step=0.1, title="MULT BB long")length2 = input(36, minval=1, title="Length BB short")mult2 = input(3.2, minval=0.001, maxval=50, step=0.1, title="MULT BB short")basis = sma(source, length)dev = mult * stdev(source, length)dev2 = mult2 * stdev(source, length2)upper = basis + dev2lower = basis - devbuyEntry = crossover(source, lower)sellEntry = crossunder(source, upper)longEntry=input(true)shortEntry=input(true)g(v, p) => round(v * (pow(10, p))) / pow(10, p)risk     = input(100)leverage = input(1.0, step = 0.5)c = g((strategy.equity * leverage / open) * (risk / 100), 4)tplong=input(0.065, step=0.005, title="Take profit % for long")sllong=input(0.04, step=0.005, title="Stop loss % for long")tpshort=input(0.025, step=0.005, title="Take profit % for short")slshort=input(0.04, step=0.005, title="Stop loss % for short")if(longEntry)    strategy.entry("long",1,c,when=buyEntry)    strategy.exit("short_tp/sl", "long", profit=close * tplong / syminfo.mintick, loss=close * sllong / syminfo.mintick, comment='LONG EXIT',  alert_message = 'closeshort')    strategy.close("long",when=sellEntry)if(shortEntry)    strategy.entry("short",0,c,when=sellEntry)    strategy.exit("short_tp/sl", "short", profit=close * tpshort / syminfo.mintick, loss=close * slshort / syminfo.mintick, comment='SHORT EXIT',  alert_message = 'closeshort')    strategy.close("short",when=buyEntry)