Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Volume Weighted Bollinger Bands Strategy

A Pine Script v4 strategy built on EMA (close, 8), SMA (average_weighting, 20) and Stdev (average_weighting, 20). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 4 settings; defaults include Source close, Length 20 and StdDev 2.0.

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 Volume Weighted Bollinger Bands Strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 6 of 6 trades.
How did Volume Weighted Bollinger Bands Strategy do on BTCUSDT 1D with default settings?
+10.02%
From 26 Jan 2024 to 21 Oct 2026, over 15 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Volume Weighted Bollinger Bands Strategy be converted to Pine Script v5?
Yes
The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
Does Volume Weighted Bollinger Bands Strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Volume Weighted Bollinger Bands Strategy run in Zeal Terminal?
Yes
It compiles in 9 ms and runs 1,000 bars in 34 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 (4)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$121,700$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. Lines are what the script plots.
Net profit
+10.02%
$10,018.70
Buy and hold
+102.5%
same period
Closed trades
15
5 won · 10 lost
Profitable
33.3%
of closed trades
Profit factor
1.18
gross profit ÷ gross loss
Max drawdown
27.49%
−$34,496.70

One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A long 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

    No stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

  • Check

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • Note

    1 setting has no label

    In the settings dialog length (line 6) shows 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 30, 31. The upgraded version below moves each call inside an if block.

  • Note

    Uses transp =, which v5 removed line 22

    transp = on line 22. v5 folds the transparency into the colour with color.new(c, transp).

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 ema → ta.ema, sma → ta.sma, stdev → ta.stdev.
  • 2 strategy calls use the when = argument (line 30, 31). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 8: ema → ta.ema
  • Line 9: ema → ta.ema
  • Line 10: ema → ta.ema
  • Line 11: ema → ta.ema
  • Line 12: vwap → ta.vwap
4 more edits
  • Line 14: sma → ta.sma
  • Line 15: stdev → ta.stdev
  • Line 18: input(type = input.integer) → input.int()
  • Line 22: transp = 95 → color.new(#198787, 95)
⋯// © Ankit_1618-//@version=4+//@version=5strategy("Volume Weighted Bollinger Bands Strategy", overlay=true)⋯mult = input(2.0, minval=0.001, maxval=50, title="StdDev")-ema8 = ema(src, 8)+ema8 = ta.ema(src, 8)-ema21 = ema(src, 21)+ema21 = ta.ema(src, 21)-ema55 = ema(src, 55)+ema55 = ta.ema(src, 55)-ema233 = ema(src, 233)+ema233 = ta.ema(src, 233)-_vwap = vwap+_vwap = ta.vwapaverage_weighting = (ema8 + ema21 + ema55 + ema233 + _vwap) / 5-basis = sma(average_weighting, length)+basis = ta.sma(average_weighting, length)-dev = mult * stdev(average_weighting, length)+dev = mult * ta.stdev(average_weighting, length)upper = basis + devlower = basis - dev-offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)+offset = input.int(0, "Offset", minval = -500, maxval = 500)plot(basis, "Basis", color=#872323, offset = offset)⋯p2 = plot(lower, "Lower", color=color.teal, offset = offset)-fill(p1, p2, title = "Background", color=#198787, transp=95)+fill(p1, p2, title = "Background", color=color.new(#198787, 95))condition_long = close > upper and close[1] > upper⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 5: input() → input.source()
  • Line 6: input() → input.int()
  • Line 7: input() → input.float()
  • Line 30: when = condition_short → if block
  • Line 31: when = condition_long → if block
⋯strategy("Volume Weighted Bollinger Bands Strategy", overlay=true)-src = input(close, title="Source")+src = input.source(close, title="Source")-length = input(20, minval=1)+length = input.int(20, minval=1)-mult = input(2.0, minval=0.001, maxval=50, title="StdDev")+mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")ema8 = ta.ema(src, 8)⋯    -strategy.close("Long", when = condition_short )+if condition_short+    strategy.close("Long" )-strategy.close("Short", when =  condition_long )+if condition_long+    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: 15 before, 21 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.

⋯// © Ankit_1618-//@version=5+//@version=6strategy("Volume Weighted Bollinger Bands Strategy", overlay=true)⋯

Settings

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

SettingDefaultType and rangeFeeds
Sourceclosesourceema8 ema21 ema55 ema233
Length (no label in the script)20int · min 1basis dev
StdDev2.0float · min 0.001 · max 50dev
Offset0int (written input.integer) · min -500 · max 500Upper Lower Basis

What it calculates

  • EMA (ema, ta.ema in v5)Source (close), 8ema8 · line 8
  • EMA (ema, ta.ema in v5)Source (close), 21ema21 · line 9
  • EMA (ema, ta.ema in v5)Source (close), 55ema55 · line 10
  • EMA (ema, ta.ema in v5)Source (close), 233ema233 · line 11
  • SMA (sma, ta.sma in v5)average_weighting, Length (20)basis · line 14
  • Stdev (stdev, ta.stdev in v5)average_weighting, Length (20)dev · line 15

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 · 20multStdDevsetting · 2.0ema8EMA→ ema8ema21EMA→ ema21ema55EMA→ ema55ema233EMA→ ema233basisSMA→ basisdevStdev→ dev_vwap_vwapvalueaverage_weightingaverage_weightingvalueupper, lowerupper · lower2 valuescondition_longcondition_longconditioncondition_shortcondition_shortconditionentry:LongOpen Longstrategy.entryentry:ShortOpen Shortstrategy.entryclose:LongClose Longstrategy.closeclose:ShortClose Shortstrategy.closeplot:19Basisplotplot:20Upperplotplot:21Lowerplotfill:BackgroundBackgroundfill

Order rules

OrderFires whenBy defaultLine
Open Long long(condition_long)On26
Open Short short(condition_short)On28
Close Longcondition_shortclose< lower and close[1] < lowerOn30
Close Shortcondition_longclose > upper and close[1] > upperOn31

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.

6/6trades 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+10.0%+102.5%1533%1.1827.5%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−6.4%+5.5%258%0.7415.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+1.3%+9.8%1443%1.551.2%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.6%+8.4%1338%2.690.2%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.0%+16.7%1644%1.130.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%1547%2.080.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.0%+148.3%1729%1.040.3%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.0%+17.1%1718%0.790.1%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%$3,807.34
Sideways market1127%$4,704.46
Falling market333%$1,506.90

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

How bad could the drawdown be?

32.9%

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

0%38%
All 15 trades
SideEntryExitBarsP&L
short11 Oct 2024 60,326.4016 Oct 2024 67,074.105−$6,747.74
long16 Oct 2024 67,074.1026 Feb 2025 88,680.40133$21,606.30
short26 Feb 2025 88,680.4023 Apr 2025 93,443.0056−$4,762.60
long23 Apr 2025 93,443.0031 Aug 2025 108,816.00130$15,373.30
short31 Aug 2025 108,816.0012 Sep 2025 115,483.0012−$6,666.36
long12 Sep 2025 115,483.0027 Sep 2025 109,643.0015−$5,839.23
short27 Sep 2025 109,643.001 Oct 2025 114,049.004−$4,405.48
long1 Oct 2025 114,049.0018 Oct 2025 106,432.0017−$7,617.26
short18 Oct 2025 106,432.007 Jan 2026 93,748.0081$12,683.70
long7 Jan 2026 93,748.0011 Jan 2026 90,504.704−$3,243.27
short11 Jan 2026 90,504.7015 Jan 2026 96,951.804−$6,447.08
long15 Jan 2026 96,951.8022 Jan 2026 89,454.707−$7,497.05
short22 Jan 2026 89,454.7024 Apr 2026 78,257.5092$11,197.30
long24 Apr 2026 78,257.5020 May 2026 76,834.4026−$1,423.12
short20 May 2026 76,834.4021 Aug 2026 73,027.0093$3,807.34

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
Volume Weighted Bollinger Bands Strategy this page—v4 strategy+10.0%1527.5%
BB21_MA200_Strategy by mohaneeema sma stdevv4 strategyNo trades on this market
Super Breakout day trading by beststockalertstdev sma emav4 strategyNo trades on this market
Super Auto Breakout Day Trade Volatile stocks by beststockalertstdev sma emav4 strategy−6.1%5129.1%
VFI strategy [based on VFI indicator published by UTS] by mohaneesma stdev emav4 strategy+181.4%8154.2%
McClellan Oscillator Strategy by sparrow_hawk_737ema sma stdevv3 strategyNo trades on this market

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 9 msYes 1,000 bars in 34 msNot measured
PineTSNo v5 and v6 only—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. 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/// © Ankit_1618//@version=4strategy("Volume Weighted Bollinger Bands Strategy", overlay=true)src = input(close, title="Source")length = input(20, minval=1)mult = input(2.0, minval=0.001, maxval=50, title="StdDev")ema8 = ema(src, 8)ema21 = ema(src, 21)ema55 = ema(src, 55)ema233 = ema(src, 233)_vwap = vwapaverage_weighting = (ema8 + ema21 + ema55 + ema233 + _vwap) / 5basis = sma(average_weighting, length)dev = mult * stdev(average_weighting, length)upper = basis + devlower = basis - devoffset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)plot(basis, "Basis", color=#872323, offset = offset)p1 = plot(upper, "Upper", color=color.teal, offset = offset)p2 = plot(lower, "Lower", color=color.teal, offset = offset)fill(p1, p2, title = "Background", color=#198787, transp=95)condition_long = close > upper and close[1] > uppercondition_short = close< lower and close[1] < lowerif (condition_long)    strategy.entry("Long", strategy.long)if (condition_short)    strategy.entry("Short", strategy.short)    strategy.close("Long", when = condition_short )strategy.close("Short", when =  condition_long )