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
- 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
DiffersTrades 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
VerifiedSame 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Length BB long | 25 | int · min 1 | basis dev |
| MULT BB long | 2.9 | float · min 0.001 · max 50 · step 0.1 | dev |
| Length BB short | 36 | int · min 1 | dev2 |
| MULT BB short | 3.2 | float · min 0.001 · max 50 · step 0.1 | dev2 |
| Long Entry (no label in the script) | true | bool | entry long exit short_tp/sl close long line 27 |
| Short Entry (no label in the script) | true | bool | entry short exit short_tp/sl close short line 31 |
| Risk (no label in the script) | 100 | int | c |
| Leverage (no label in the script) | 1.0 | float · step 0.5 | c |
| Take profit % for long | 0.065 | float · step 0.005 | exit short_tp/sl |
| Stop loss % for long | 0.04 | float · step 0.005 | exit short_tp/sl |
| Take profit % for short | 0.025 | float · step 0.005 | exit short_tp/sl |
| Stop loss % for short | 0.04 | float · step 0.005 | exit short_tp/sl |
What it calculates
- SMA (
sma,ta.smain v5)source, Length BB long (25)basis · line 10 - Stdev (
stdev,ta.stdevin v5)source, Length BB long (25)dev · line 11 - Stdev (
stdev,ta.stdevin v5)source, Length BB short (36)dev2 · line 12 - Crossover (
crossover,ta.crossoverin v5)source, lowerbuyEntry · line 15 - Crossunder (
crossunder,ta.crossunderin 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open long long | buyEntry | On | 28 |
| Exit short_tp/sl stop and limit | (longEntry) | On | 29 |
| Close long | sellEntry | On | 30 |
| Open short short | sellEntry | On | 32 |
| Exit short_tp/sl stop and limit | (shortEntry) | On | 33 |
| Close short | buyEntry | On | 34 |
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.
- 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | −20.4% | +102.5% | 7 | 14% | 0.11 | 22.3% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −14.2% | +5.5% | 8 | 25% | 0.36 | 17.8% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −24.4% | +9.8% | 14 | 29% | 0.29 | 30.6% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −11.9% | +8.4% | 14 | 36% | 0.65 | 17.5% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −19.1% | +16.7% | 5 | 0% | 0.00 | 19.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −17.4% | +21.5% | 9 | 22% | 0.32 | 17.4% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +5.5% | +148.3% | 10 | 60% | 1.31 | 8.3% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −5.1% | +17.1% | 7 | 43% | 0.70 | 18.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 1 | 100% | $2,400.75 |
| Sideways market | 4 | 0% | −$14,970.10 |
| Falling market | 2 | 0% | −$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.
All 7 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 22 May 2024 70,148.30 | 23 May 2024 68,419.20 | 1 | $2,400.75 |
| long | 28 Feb 2025 84,708.60 | 28 Feb 2025 81,320.20 | 0 | −$4,138.38 |
| short | 24 Apr 2025 93,691.10 | 2 May 2025 97,550.70 | 8 | −$4,078.87 |
| long | 2 Feb 2026 76,968.20 | 3 Feb 2026 73,818.70 | 1 | −$3,785.21 |
| long | 7 Feb 2026 70,580.30 | 7 Feb 2026 67,757.00 | 0 | −$4,076.56 |
| long | 4 Jun 2026 64,142.80 | 4 Jun 2026 61,577.00 | 0 | −$3,333.72 |
| short | 24 Aug 2026 77,734.00 | 25 Aug 2026 80,893.70 | 1 | −$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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Improved Bollinger Swing Strategy Stock Nasdaq this page | — | v4 strategy | −20.4% | 7 | 22.3% |
| Double Bollinger Binary Options by Trade_by_DB | sma stdev | v5 strategy | No trades on this market | ||
| 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% |
| Bollinger Stop Strategy by ROBO_Trading | sma stdev | v5 strategy | −32.0% | 41 | 61.5% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 12 ms | With a workaround 1,000 bars in 38 ms | Not measured |
| PineTS | No 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)