Pine Script v5 · Strategy
Buying Selling Volume Strategy
A Pine Script v5 strategy built on VWAP (hlc3), EMA (vol, 20) and SMA (src, 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. 9 settings; defaults include Custom Timeframe 60, 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 Buying Selling Volume Strategy repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did Buying Selling Volume Strategy do on BTCUSDT 1D with default settings?
- Not measured
- It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its entry conditions never all held on this data. It closed no trades on the other markets either. A backtest, not investment advice.
- Does Buying Selling Volume Strategy run in Pine Script v6?
- No
- The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L62:C98: the argument 'step' is specified more than once. The v6 version is shown for reference and is not offered as a download.
- Does Buying Selling Volume Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Buying Selling Volume Strategy run in Zeal Terminal?
- Yes
- It compiles in 37 ms and runs 1,000 bars in 97 ms, in the browser.
BTCUSDT · 1D · default settings
- VWAP
- EMA
- EMA
- EMA
- SMA
- Stdev
- SMA
- Winning trade
- Losing trade
- Equity
- Buy and hold
Needs BINANCE:BTCUSDT 60 data, not available: a lower timeframe than the chart; the engine does not evaluate intrabar data Values that depend on it are empty on this chart.
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- $0.00
One run with the author's default settings, $1,000,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.
-
Likely bug
ta.sma(true_range*100/request.security(syminfo.tickerid, "D", close), 14) ignores the settings line 61
Line 61 hard-codes 14 where line 44 uses “Length”. Changing those settings moves one band but not this one.
ta.sma(true_range*100/request.security(syminfo.tickerid, "D", close), 14)ta.sma(true_range*100/request.security(syminfo.tickerid, "D", close), length) -
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
4 settings have no label
In the settings dialog customTimeframe (line 8), allow_long (line 9), allow_short (line 10), length (line 41) 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 91, 92, 94, 95. 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Entry Settings | |||
| Custom Timeframe (no label in the script) | 60 | timeframe | xVolume xHigh xLow xClose tavol20 tabv20 tasv20 xbvp xbpn xspv xspn xtasma xstdev |
| Allow long (no label in the script) | true | bool | entry long close long line 90 |
| Allow short (no label in the script) | false | bool | entry short close short line 93 |
| Volatility Settings | |||
| Length (no label in the script) | 20 | int · min 1 | xtasma xstdev |
| StdDev | 2.0 | float · min 0.001 · max 50 | dev |
| Dynamic Risk Management | |||
| TP Multiplier for Long entries | 100.0 | float · step 0.5 | Profit_Ticks_long |
| SL Multiplier for Long entries | 1.0 | float · step 0.5 | Loss_Ticks_long |
| TP Multiplier for Short entries | 100.0 | float · step 0.5 | Profit_Ticks_short |
| SL Multiplier for Short entries | 5.0 | float · step 0.5 | Loss_Ticks_short |
What it calculates
- VWAPhlc3
weekly_vwap · line 6 - EMAvol, 20
tavol20 · line 22 - EMABV, 20
tabv20 · line 23 - EMASV, 20
tasv20 · line 24 - SMAsrc, Length (20)
xtasma · line 44 - Stdevsrc, Length (20)
xstdev · line 45 - SMAtrue_range*100/request.security(syminfo.tickerid, "D", close), 14
atr_range · line 61
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.
The script has 77 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open long long | longOriginalminus > upper and BPcon > SPcon and close > weekly_vwap | On | 91 |
| Close long | longExitSignal_originalshortOriginal or tpLong_trigger or slLong_Trigger | On | 92 |
| Open short short | shortOriginalminus > upper and BPcon < SPcon and close< weekly_vwap | On | 94 |
| Close short | longOriginalminus > upper and BPcon > SPcon and close > weekly_vwap | On | 95 |
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.
- ClearHigher-timeframe data18 request.security call(s), none with lookahead on.
- 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
Not run on other markets: the script requests BINANCE:BTCUSDT 60, and that data is not available here (a lower timeframe than the chart; the engine does not evaluate intrabar data). Its results would rest on empty values.
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 |
|---|---|---|---|---|---|
| Buying Selling Volume Strategy this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| VWAP and BB strategy [EEMANI] by mohanee | ema vwap sma stdev | v4 strategy | No trades on this market | ||
| Long only strategy VWAP with BB and Golden Cross EMA50-200 by SoftKill21 | ema vwap sma stdev | v4 strategy | No trades on this market | ||
| Volume Weighted Bollinger Bands Strategy by Ankit_1618 | ema sma stdev | v4 strategy | +10.0% | 15 | 27.5% |
| BB21_MA200_Strategy by mohanee | ema sma stdev | v4 strategy | No trades on this market | ||
| ZVWAP strategy by mohanee | sma ema vwap | v4 strategy | +614.4% | 13 | 748.5% |
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.
- 4 strategy calls use the when = argument (line 91, 92, 94, 95). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- No v6-only features. v6 is not needed to run this script.
Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 91: when = longOriginal → if block
- Line 92: when = longExitSignal_original → if block
- Line 94: when = shortOriginal → if block
- Line 95: when = longOriginal → if block
⋯if(allow_long)- strategy.entry("long", strategy.long, when=longOriginal) + if longOriginal+ strategy.entry("long", strategy.long) - strategy.close("long", when= longExitSignal_original) //or shortNew+ if longExitSignal_original+ strategy.close("long") //or shortNewif(allow_short)- strategy.entry("short", strategy.short, when=shortOriginal ) + if shortOriginal+ strategy.entry("short", strategy.short ) - strategy.close("short", when= longOriginal) //or shortNew+ if longOriginal+ strategy.close("short") //or shortNewDoes it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L62:C98: the argument 'step' is specified more than once. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯//@ exlux99 update-//@version=5+//@version=6strategy('Buying Selling Volume Strategy', format=format.volume, precision=0, overlay=false)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 37 ms | With a workaround 1,000 bars in 97 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“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/// © original author ceyhun//@ exlux99 update//@version=5strategy('Buying Selling Volume Strategy', format=format.volume, precision=0, overlay=false)weekly_vwap = request.security(syminfo.tickerid, "W", ta.vwap(hlc3))vi = falsecustomTimeframe = input.timeframe("60", group="Entry Settings")allow_long = input.bool(true, group="Entry Settings")allow_short = input.bool(false, group="Entry Settings")xVolume = request.security(syminfo.tickerid, customTimeframe, volume)xHigh = request.security(syminfo.tickerid, customTimeframe, high)xLow = request.security(syminfo.tickerid, customTimeframe, low)xClose = request.security(syminfo.tickerid, customTimeframe, close)BV = xHigh == xLow ? 0 : xVolume * (xClose - xLow) / (xHigh - xLow)SV = xHigh == xLow ? 0 : xVolume * (xHigh - xClose) / (xHigh - xLow)vol = xVolume > 0 ? xVolume : 1TP = BV + SVBPV = BV / TP * volSPV = SV / TP * volTPV = BPV + SPVtavol20 = request.security(syminfo.tickerid, customTimeframe, ta.ema(vol, 20))tabv20= request.security(syminfo.tickerid, customTimeframe, ta.ema(BV, 20))tasv20= request.security(syminfo.tickerid, customTimeframe, ta.ema(SV, 20))VN = vol / tavol20BPN = BV / tabv20 * VN * 100SPN = SV / tasv20 * VN * 100TPN = BPN + SPNxbvp = request.security(syminfo.tickerid, customTimeframe,-math.abs(BPV))xbpn = request.security(syminfo.tickerid, customTimeframe,-math.abs(BPN))xspv = request.security(syminfo.tickerid, customTimeframe,-math.abs(SPV))xspn = request.security(syminfo.tickerid, customTimeframe,-math.abs(SPN))BPc1 = BPV > SPV ? BPV : xbvpBPc2 = BPN > SPN ? BPN : xbpnSPc1 = SPV > BPV ? SPV : xspvSPc2 = SPN > BPN ? SPN : xspnBPcon = vi ? BPc2 : BPc1SPcon = vi ? SPc2 : SPc1minus = BPcon + SPconplot(minus, color = BPcon > SPcon ? color.green : color.red , style=plot.style_columns) length = input.int(20, minval=1, group="Volatility Settings")src = minus//input(close, title="Source")mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev", group="Volatility Settings")xtasma = request.security(syminfo.tickerid, customTimeframe, ta.sma(src, length))xstdev = request.security(syminfo.tickerid, customTimeframe, ta.stdev(src, length))basis = xtasmadev = mult * xstdevupper = basis + devlower = basis - devplot(basis, "Basis", color=#FF6D00, offset = 0)p1 = plot(upper, "Upper", color=#2962FF, offset = 0)p2 = plot(lower, "Lower", color=#2962FF, offset = 0)fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))// Original alongOriginal = minus > upper and BPcon > SPcon and close > weekly_vwapshortOriginal = minus > upper and BPcon < SPcon and close< weekly_vwaphigh_daily = request.security(syminfo.tickerid, "D", high)low_daily = request.security(syminfo.tickerid, "D", low)close_daily = request.security(syminfo.tickerid, "D", close)true_range = math.max(high_daily - low_daily, math.abs(high_daily - close_daily[1]), math.abs(low_daily - close_daily[1]))atr_range = ta.sma(true_range*100/request.security(syminfo.tickerid, "D", close), 14)ProfitTarget_Percent_long = input.float(100.0, title='TP Multiplier for Long entries ', step=0.5, step=0.5, group='Dynamic Risk Management')Profit_Ticks_long = close + (close * (atr_range * ProfitTarget_Percent_long))/100LossTarget_Percent_long = input.float(1.0, title='SL Multiplier for Long entries', step=0.5, group='Dynamic Risk Management')Loss_Ticks_long = close - (close * (atr_range * LossTarget_Percent_long ))/100ProfitTarget_Percent_short = input.float(100.0, title='TP Multiplier for Short entries ', step=0.5, step=0.5, group='Dynamic Risk Management')Profit_Ticks_short = close - (close * (atr_range*ProfitTarget_Percent_short))/100LossTarget_Percent_short = input.float(5.0, title='SL Multiplier for Short entries', step=0.5, group='Dynamic Risk Management')Loss_Ticks_short = close + (close * (atr_range*LossTarget_Percent_short))/100var longOpened_original = falsevar int timeOfBuyLong = navar float tpLong_long_original = navar float slLong_long_original = nalong_entryx = longOriginallongEntry_original = long_entryx and not longOpened_original if longEntry_original longOpened_original := true tpLong_long_original := Profit_Ticks_long slLong_long_original := Loss_Ticks_long timeOfBuyLong := time //lowest_low_var_sl := lowest_low tpLong_trigger = longOpened_original[1] and ((close > tpLong_long_original) or (high > tpLong_long_original)) //or high > lowest_low_var_tpslLong_Trigger = longOpened_original[1] and ((close < slLong_long_original) or (low < slLong_long_original)) //or low < lowest_low_var_sllongExitSignal_original = shortOriginal or tpLong_trigger or slLong_Trigger if(longExitSignal_original) longOpened_original := false tpLong_long_original := na slLong_long_original := naif(allow_long) strategy.entry("long", strategy.long, when=longOriginal) strategy.close("long", when= longExitSignal_original) //or shortNewif(allow_short) strategy.entry("short", strategy.short, when=shortOriginal ) strategy.close("short", when= longOriginal) //or shortNew