Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

ZVWAP strategy

A Pine Script v4 strategy built on SMA (source1-mean, 2, pds), EMA (close, 55) and VWAP (hlc3). It has 4 order rules, 2 entries among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade is 3 contracts and pays no commission. 6 settings; defaults include length 13, OverSold Line -0.5 and OverBought Line 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 ZVWAP strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 1 of 1 trades.
How did ZVWAP strategy do on BTCUSDT 1D with default settings?
+614.37%
From 26 Jan 2024 to 21 Oct 2026, over 13 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can ZVWAP 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 ZVWAP strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does ZVWAP strategy run in Zeal Terminal?
Yes
It compiles in 16 ms and runs 1,000 bars in 59 ms, in the browser.

BTCUSDT · 1D · default settings

  • Middle Line
  • OB High
  • OB Low
  • OS High
  • OS Low
  • ZVWAP
  • 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 (6)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctMiddle Line$76,472$20,253Equity from $10,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. Zeal Terminal's engine currently reads an order side written as long = true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 37, 39) so the engine trades the way the script says.
Net profit
+614.37%
$61,437.40
Buy and hold
+102.5%
same period
Closed trades
13
7 won · 6 lost
Profitable
53.8%
of closed trades
Profit factor
1.68
gross profit ÷ gross loss
Max drawdown
748.49%
−$74,849.00

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

    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 37, 39, 42, 43. The upgraded version below moves each call inside an if block.

  • Note

    Uses long =, which v5 renamed line 37

    long = on line 37, 39. v5 writes it as direction = strategy.long or strategy.short.

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 sum → math.sum, sqrt → math.sqrt, sma → ta.sma, pow → math.pow, ema → ta.ema, vwap → ta.vwap, crossover → ta.crossover, crossunder → ta.crossunder.
  • 4 strategy calls use the when = argument (line 37, 39, 42, 43). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

Same 13 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: sum → math.sum
  • Line 8: sum → math.sum
  • Line 9: sqrt → math.sqrt
  • Line 9: sma → ta.sma
  • Line 9: pow → math.pow
8 more edits
  • Line 29: ema → ta.ema
  • Line 30: ema → ta.ema
  • Line 31: vwap → ta.vwap
  • Line 35: crossover → ta.crossover
  • Line 37: long = true → direction = strategy.long
  • Line 39: long = true → direction = strategy.long
  • Line 39: crossover → ta.crossover
  • Line 43: crossunder → ta.crossunder
⋯// © mohanee-//@version=4+//@version=5//This is based on Z distance from VWAP by Lazybear⋯calc_zvwap(pds, source1) =>-    mean = sum(volume*source1,pds)/sum(volume,pds)+    mean = math.sum(volume*source1,pds)/math.sum(volume,pds)-    vwapsd = sqrt(sma(pow(source1-mean, 2), pds) )+    vwapsd = math.sqrt(ta.sma(math.pow(source1-mean, 2), pds) )    (close-mean)/vwapsd⋯plot(zvwapVal,title="ZVWAP",color=color.purple, linewidth=2)-longEmaVal=ema(close,slowEma)+longEmaVal=ta.ema(close,slowEma)-shortEmaVal=ema(close,fastEma)  +shortEmaVal=ta.ema(close,fastEma)  -vwapVal=vwap(hlc3)+vwapVal=ta.vwap(hlc3)zvwapDipped=false⋯    zvwapDipped := zvwapDipped or zvwapVal[i]<=buyLine-longCondition=  shortEmaVal > longEmaVal  and zvwapDipped and  crossover(zvwapVal,0)+longCondition=  shortEmaVal > longEmaVal  and zvwapDipped and  ta.crossover(zvwapVal,0)barcolor(longCondition ? color.yellow: na)-strategy.entry(id="ZVWAPLE", long=true,  when= longCondition  and strategy.position_size<1) +strategy.entry(id="ZVWAPLE", direction = strategy.long,  when= longCondition  and strategy.position_size<1) //Add-strategy.entry(id="ZVWAPLE", comment="Add", long=true,  when= strategy.position_size>1 and close<strategy.position_avg_price and crossover(zvwapVal,0)) +strategy.entry(id="ZVWAPLE", comment="Add", direction = strategy.long,  when= strategy.position_size>1 and close<strategy.position_avg_price and ta.crossover(zvwapVal,0)) //calculate stop Loss⋯strategy.close(id="ZVWAPLE",comment="SL Exit",    when=close<stopLossVal)   //close all on stop loss-strategy.close(id="ZVWAPLE",comment="TPExitAll",    qty=strategy.position_size ,   when= crossunder(zvwapVal,sellLine))   //close all      zvwapVal>sellLine+strategy.close(id="ZVWAPLE",comment="TPExitAll",    qty=strategy.position_size ,   when= ta.crossunder(zvwapVal,sellLine))   //close all      zvwapVal>sellLine

Clean v5

VerifiedDownload the v5 script

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

  • Line 6: input() → input.int()
  • Line 15: input() → input.float()
  • Line 16: input() → input.float()
  • Line 17: input() → input.int()
  • Line 18: input() → input.int()
  • Line 19: input() → input.int()
4 more edits
  • Line 37: when = longCondition and strategy.position_size<1 → if block
  • Line 39: when = strategy.position_size>1 and close<strategy.position_avg_price and ta.crossover(zvwapVal,0) → if block
  • Line 42: when = close<stopLossVal → if block
  • Line 43: when = ta.crossunder(zvwapVal,sellLine) → if block
⋯strategy(title="ZVWAP[LB] strategy", overlay=false,pyramiding=2, default_qty_type=strategy.fixed, default_qty_value=3,    initial_capital=10000, currency=currency.USD)-length=input(13,"length")+length=input.int(13,"length")calc_zvwap(pds, source1) =>⋯lowerBottom=-2.0 //input(-2.0)-buyLine=input(-0.5, title="OverSold Line",minval=-2, maxval=3)+buyLine=input.float(-0.5, title="OverSold Line",minval=-2, maxval=3)-sellLine=input(2.0, title="OverBought Line",minval=-2, maxval=3)+sellLine=input.float(2.0, title="OverBought Line",minval=-2, maxval=3)-fastEma=input(13, title="Fast EMA",minval=1, maxval=50)+fastEma=input.int(13, title="Fast EMA",minval=1, maxval=50)-slowEma=input(55, title="Slow EMA",minval=10, maxval=200)+slowEma=input.int(55, title="Slow EMA",minval=10, maxval=200)-stopLoss =input(5, title="Stop Loss",minval=1) +stopLoss =input.int(5, title="Stop Loss",minval=1) hline(0, title="Middle Line", linestyle=hline.style_dotted, color=color.green)⋯barcolor(longCondition ? color.yellow: na)-strategy.entry(id="ZVWAPLE", direction = strategy.long,  when= longCondition  and strategy.position_size<1) +if longCondition  and strategy.position_size<1+    strategy.entry(id="ZVWAPLE", direction = strategy.long) //Add-strategy.entry(id="ZVWAPLE", comment="Add", direction = strategy.long,  when= strategy.position_size>1 and close<strategy.position_avg_price and ta.crossover(zvwapVal,0)) +if strategy.position_size>1 and close<strategy.position_avg_price and ta.crossover(zvwapVal,0)+    strategy.entry(id="ZVWAPLE", comment="Add", direction = strategy.long) //calculate stop LossstopLossVal =  strategy.position_avg_price -  (strategy.position_avg_price*stopLoss*0.01)-strategy.close(id="ZVWAPLE",comment="SL Exit",    when=close<stopLossVal)   //close all on stop loss+if close<stopLossVal+    strategy.close(id="ZVWAPLE",comment="SL Exit")   //close all on stop loss-strategy.close(id="ZVWAPLE",comment="TPExitAll",    qty=strategy.position_size ,   when= ta.crossunder(zvwapVal,sellLine))   //close all      zvwapVal>sellLine+if ta.crossunder(zvwapVal,sellLine)+    strategy.close(id="ZVWAPLE",comment="TPExitAll",    qty=strategy.position_size )   //close all      zvwapVal>sellLine

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: 13 before, 0 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.

⋯// © mohanee-//@version=5+//@version=6//This is based on Z distance from VWAP by Lazybear⋯

Settings

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

SettingDefaultType and rangeFeeds
length13intzvwapVal
OverSold Line-0.5float · min -2 · max 3zvwapDipped
OverBought Line2.0float · min -2 · max 3close ZVWAPLE
Fast EMA13int · min 1 · max 50shortEmaVal
Slow EMA55int · min 10 · max 200longEmaVal
Stop Loss5int · min 1stopLossVal

What it calculates

  • SMA (sma, ta.sma in v5)pow(source1-mean, 2), pdsvwapsd · line 9
  • EMA (ema, ta.ema in v5)close, Slow EMA (55)longEmaVal · line 29
  • EMA (ema, ta.ema in v5)close, Fast EMA (13)shortEmaVal · line 30
  • VWAP (vwap, ta.vwap in v5)hlc3vwapVal · line 31

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 dataslowEmaSlow EMAsetting · 55fastEmaFast EMAsetting · 13hlc3hlc3price datahlc3 · volumehlc3 · volumeprice datavolumevolumeprice datalengthlengthsetting · 13stopLossStop Losssetting · 5buyLineOverSold Linesetting · -0.5sellLineOverBought Linesetting · 2.0vwapsdSMA→ vwapsdlongEmaValEMA→ longEmaValshortEmaValEMA→ shortEmaValvwapValVWAP→ vwapValmeanmeanvaluezvwapValzvwapValvaluestopLossValstopLossValvaluezvwapDippedzvwapDippedconditionlongConditionlongConditionconditionentry:ZVWAPLEOpen ZVWAPLEstrategy.entryclose:ZVWAPLEClose ZVWAPLEstrategy.closehline:20Middle Linehlineplot:21OB Highplotplot:22OB Lowplotfill:23Fillfill × 2plot:24OS Highplotplot:25OS Lowplotfill:26Fillfill × 2plot:28ZVWAPplotbarcolor:36barcolorbarcolor

Order rules

OrderFires whenBy defaultLine
Open ZVWAPLE longlongCondition and strategy.position_size<1On37
Open ZVWAPLE longstrategy.position_size>1 and close<strategy.position_avg_price and crossover(zvwapVal,0)On39
Close ZVWAPLEclose<stopLossValOn42
Close ZVWAPLEcrossunder(zvwapVal,sellLine)On43

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.

1/1trades 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+614.4%+102.5%1354%1.68748.5%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+145.4%+5.5%1354%1.51115.9%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+0.9%+9.8%1741%1.0135.7%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+19.8%+8.4%1759%3.497.5%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+3.1%+16.7%757%3.111.5%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.1%+21.5%1464%1.090.4%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+3.7%+148.3%1958%1.2211.2%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+3.9%+17.1%1782%2.452.6%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 market1060%$79,181.20
Sideways market333%−$17,743.80
Falling market0—$0.00

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

How bad could the drawdown be?

11,858.8%

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

0%13,638%
All 13 trades
SideEntryExitBarsP&L
long26 Mar 2024 69,880.003 Apr 2024 65,464.008−$13,248.00
long5 Apr 2024 68,487.8014 Apr 2024 63,924.509−$13,689.80
long23 Apr 2024 66,819.301 May 2024 60,672.008−$18,441.90
long26 Apr 2024 64,498.301 May 2024 60,672.005−$11,479.00
long4 Jun 2024 68,809.9019 Jun 2024 65,175.3015−$10,903.70
long12 Oct 2024 62,540.0017 Oct 2024 67,620.005$15,240.00
long7 Nov 2024 75,572.008 Nov 2024 75,857.901$857.70
long3 Jan 2025 96,984.8019 Jan 2025 104,556.0016$22,714.30
long15 Jan 2025 96,560.9019 Jan 2025 104,556.004$23,986.10
long8 Jun 2025 105,552.0012 Jul 2025 117,528.0034$35,926.50
long24 Jun 2025 105,334.0012 Jul 2025 117,528.0018$36,581.20
long8 Aug 2025 117,472.0026 Aug 2025 110,112.0018−$22,080.10
long19 Sep 2026 80,883.9023 Sep 2026 86,208.604$15,974.10

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
ZVWAP strategy this page—v4 strategy+614.4%13748.5%
Ultimate Oscillator [Long] Strategy by mohaneesma vwap emav4 strategyNo trades on this market
JBravo Swing with GoGo Juice by bradvaughnsma ema vwapv4 strategy+68.7%9322.3%
VWAP and BB strategy [EEMANI] by mohaneeema vwap smav4 strategyNo trades on this market
Buying Selling Volume Strategy by exlux99vwap ema smav5 strategyNo trades on this market
Long only strategy VWAP with BB and Golden Cross EMA50-200 by SoftKill21ema vwap smav4 strategyNo trades on this market

Where it runs

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

Zeal Terminal's engine currently reads an order side written as long = true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 37, 39) 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/// © mohanee//@version=4//This is based on Z distance from VWAP by Lazybearstrategy(title="ZVWAP[LB] strategy", overlay=false,pyramiding=2, default_qty_type=strategy.fixed, default_qty_value=3,    initial_capital=10000, currency=currency.USD)length=input(13,"length")calc_zvwap(pds, source1) =>    mean = sum(volume*source1,pds)/sum(volume,pds)    vwapsd = sqrt(sma(pow(source1-mean, 2), pds) )    (close-mean)/vwapsdupperTop=2.5  //input(2.5)upperBottom=2.0  //input(2.0)lowerTop=-0.5  //input(-0.5)lowerBottom=-2.0 //input(-2.0)buyLine=input(-0.5, title="OverSold Line",minval=-2, maxval=3)sellLine=input(2.0, title="OverBought Line",minval=-2, maxval=3)fastEma=input(13, title="Fast EMA",minval=1, maxval=50)slowEma=input(55, title="Slow EMA",minval=10, maxval=200)stopLoss =input(5, title="Stop Loss",minval=1) hline(0, title="Middle Line", linestyle=hline.style_dotted, color=color.green)ul1=plot(upperTop, "OB High")ul2=plot(upperBottom, "OB Low")fill(ul1,ul2, color=color.red)ll1=plot(lowerTop, "OS High")ll2=plot(lowerBottom, "OS Low")fill(ll1,ll2, color=color.green)zvwapVal=calc_zvwap(length,close)plot(zvwapVal,title="ZVWAP",color=color.purple, linewidth=2)longEmaVal=ema(close,slowEma)shortEmaVal=ema(close,fastEma)  vwapVal=vwap(hlc3)zvwapDipped=falsefor i = 1 to 10    zvwapDipped := zvwapDipped or zvwapVal[i]<=buyLinelongCondition=  shortEmaVal > longEmaVal  and zvwapDipped and  crossover(zvwapVal,0)barcolor(longCondition ? color.yellow: na)strategy.entry(id="ZVWAPLE", long=true,  when= longCondition  and strategy.position_size<1) //Addstrategy.entry(id="ZVWAPLE", comment="Add", long=true,  when= strategy.position_size>1 and close<strategy.position_avg_price and crossover(zvwapVal,0)) //calculate stop LossstopLossVal =  strategy.position_avg_price -  (strategy.position_avg_price*stopLoss*0.01)strategy.close(id="ZVWAPLE",comment="SL Exit",    when=close<stopLossVal)   //close all on stop lossstrategy.close(id="ZVWAPLE",comment="TPExitAll",    qty=strategy.position_size ,   when= crossunder(zvwapVal,sellLine))   //close all      zvwapVal>sellLine