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
- 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
VerifiedSame 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⋯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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Source | close | source | ema8 ema21 ema55 ema233 |
| Length (no label in the script) | 20 | int · min 1 | basis dev |
| StdDev | 2.0 | float · min 0.001 · max 50 | dev |
| Offset | 0 | int (written input.integer) · min -500 · max 500 | Upper Lower Basis |
What it calculates
- EMA (
ema,ta.emain v5)Source (close), 8ema8 · line 8 - EMA (
ema,ta.emain v5)Source (close), 21ema21 · line 9 - EMA (
ema,ta.emain v5)Source (close), 55ema55 · line 10 - EMA (
ema,ta.emain v5)Source (close), 233ema233 · line 11 - SMA (
sma,ta.smain v5)average_weighting, Length (20)basis · line 14 - Stdev (
stdev,ta.stdevin 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | (condition_long) | On | 26 |
| Open Short short | (condition_short) | On | 28 |
| Close Long | condition_shortclose< lower and close[1] < lower | On | 30 |
| Close Short | condition_longclose > upper and close[1] > upper | On | 31 |
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 | +10.0% | +102.5% | 15 | 33% | 1.18 | 27.5% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −6.4% | +5.5% | 25 | 8% | 0.74 | 15.4% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +1.3% | +9.8% | 14 | 43% | 1.55 | 1.2% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.6% | +8.4% | 13 | 38% | 2.69 | 0.2% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.0% | +16.7% | 16 | 44% | 1.13 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 15 | 47% | 2.08 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.0% | +148.3% | 17 | 29% | 1.04 | 0.3% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.0% | +17.1% | 17 | 18% | 0.79 | 0.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 1 | 100% | $3,807.34 |
| Sideways market | 11 | 27% | $4,704.46 |
| Falling market | 3 | 33% | $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.
All 15 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 11 Oct 2024 60,326.40 | 16 Oct 2024 67,074.10 | 5 | −$6,747.74 |
| long | 16 Oct 2024 67,074.10 | 26 Feb 2025 88,680.40 | 133 | $21,606.30 |
| short | 26 Feb 2025 88,680.40 | 23 Apr 2025 93,443.00 | 56 | −$4,762.60 |
| long | 23 Apr 2025 93,443.00 | 31 Aug 2025 108,816.00 | 130 | $15,373.30 |
| short | 31 Aug 2025 108,816.00 | 12 Sep 2025 115,483.00 | 12 | −$6,666.36 |
| long | 12 Sep 2025 115,483.00 | 27 Sep 2025 109,643.00 | 15 | −$5,839.23 |
| short | 27 Sep 2025 109,643.00 | 1 Oct 2025 114,049.00 | 4 | −$4,405.48 |
| long | 1 Oct 2025 114,049.00 | 18 Oct 2025 106,432.00 | 17 | −$7,617.26 |
| short | 18 Oct 2025 106,432.00 | 7 Jan 2026 93,748.00 | 81 | $12,683.70 |
| long | 7 Jan 2026 93,748.00 | 11 Jan 2026 90,504.70 | 4 | −$3,243.27 |
| short | 11 Jan 2026 90,504.70 | 15 Jan 2026 96,951.80 | 4 | −$6,447.08 |
| long | 15 Jan 2026 96,951.80 | 22 Jan 2026 89,454.70 | 7 | −$7,497.05 |
| short | 22 Jan 2026 89,454.70 | 24 Apr 2026 78,257.50 | 92 | $11,197.30 |
| long | 24 Apr 2026 78,257.50 | 20 May 2026 76,834.40 | 26 | −$1,423.12 |
| short | 20 May 2026 76,834.40 | 21 Aug 2026 73,027.00 | 93 | $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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Volume Weighted Bollinger Bands Strategy this page | — | v4 strategy | +10.0% | 15 | 27.5% |
| BB21_MA200_Strategy by mohanee | ema sma stdev | v4 strategy | No trades on this market | ||
| Super Breakout day trading by beststockalert | stdev sma ema | v4 strategy | No trades on this market | ||
| Super Auto Breakout Day Trade Volatile stocks by beststockalert | stdev sma ema | v4 strategy | −6.1% | 51 | 29.1% |
| VFI strategy [based on VFI indicator published by UTS] by mohanee | sma stdev ema | v4 strategy | +181.4% | 8 | 154.2% |
| McClellan Oscillator Strategy by sparrow_hawk_737 | ema sma stdev | v3 strategy | No trades on this market | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 9 ms | Yes 1,000 bars in 34 ms | Not measured |
| PineTS | No 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 )