Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

VWMA_withATRstops_strategy

A Pine Script v4 strategy built on VWMA (close, 33), RSI (vwmaVal, 14) and ATR (33). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 20% of equity and pays no commission. 6 settings; defaults include VWMA Length 33, ATR length 33 and ATR Multiplier 3.5.

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 VWMA_withATRstops_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 VWMA_withATRstops_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; it opened a long position that was still open on the last bar, so there is no result to report. On ETHUSDT 1D it did trade; that row of the markets table below has its figures. A backtest, not investment advice.
Can VWMA_withATRstops_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 VWMA_withATRstops_strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does VWMA_withATRstops_strategy run in Zeal Terminal?
Yes
It compiles in 11 ms and runs 1,000 bars in 44 ms, in the browser.

BTCUSDT · 1D · default settings

  • VWMA
  • 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,000AprJulOct2025AprJulOct2026AprJulOct$11,856$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 (line 36) so the engine trades the way the script says.
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
31.42%
−$3,141.73

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 36, 41. The upgraded version below moves each call inside an if block.

  • Note

    Uses iff(), which v5 removed line 25

    iff() on line 25, 25, 25, 26, 26. v5 writes it as the ternary c ? a : b.

  • Note

    Uses long =, which v5 renamed line 36

    long = on line 36. 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 vwma → ta.vwma, rsi → ta.rsi, atr → ta.atr, max → math.max, min → math.min, crossunder → ta.crossunder.
  • 2 strategy calls use the when = argument (line 36, 41). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 15: vwma → ta.vwma
  • Line 22: rsi → ta.rsi
  • Line 23: atr → ta.atr
  • Line 25: iff(c, a, b) → (c ? a : b)
  • Line 25: max → math.max
7 more edits
  • Line 25: iff(c, a, b) → (c ? a : b)
  • Line 25: min → math.min
  • Line 25: iff(c, a, b) → (c ? a : b)
  • Line 26: iff(c, a, b) → (c ? a : b)
  • Line 26: iff(c, a, b) → (c ? a : b)
  • Line 36: long = true → direction = strategy.long
  • Line 41: crossunder → ta.crossunder
⋯// © mohanee-//@version=4+//@version=5//strategy("", overlay=true)⋯stopLoss=input(5,title="Stop Loss",minval=1)-vwmaVal=vwma(close, vwmalength)+vwmaVal=ta.vwma(close, vwmalength)//vwmaVal2=vwma(close, vwmalength2)⋯//rsi of vwma Longterm-rsiofVwmaVal=rsi(vwmaVal,rsiofVwmaLength)+rsiofVwmaVal=ta.rsi(vwmaVal,rsiofVwmaLength)-xATR = atr(nATRPeriod)+xATR = ta.atr(nATRPeriod)nLoss = nATRMultip * xATR-xATRTrailingStop:= iff(close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), close - nLoss), iff(close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), close + nLoss), iff(close > nz(xATRTrailingStop[1], 0), close - nLoss, close + nLoss)))+xATRTrailingStop:= (close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0) ? math.max(nz(xATRTrailingStop[1]), close - nLoss) : (close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0) ? math.min(nz(xATRTrailingStop[1]), close + nLoss) : (close > nz(xATRTrailingStop[1], 0) ? close - nLoss : close + nLoss)))-pos:=   iff(close[1] < nz(xATRTrailingStop[1], 0) and close > nz(xATRTrailingStop[1], 0), 1,        iff(close[1] > nz(xATRTrailingStop[1], 0) and close < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0))) +pos:=   (close[1] < nz(xATRTrailingStop[1], 0) and close > nz(xATRTrailingStop[1], 0) ? 1 : (close[1] > nz(xATRTrailingStop[1], 0) and close < nz(xATRTrailingStop[1], 0) ? -1 : nz(pos[1], 0))) color1 = pos == -1 ? color.red: pos == 1 ? color.green : color.blue ⋯//strategy.entry(id="VWMA LE", long=true, qty=qty1, when= close >vwmaVal and open>vwmaVal and close>open and close > xATRTrailingStop and xATRTrailingStop>  vwmaVal)-strategy.entry(id="VWMA LE", long=true, qty=qty1, when= rsiofVwmaVal>=30 and  close>open and close>vwmaVal and pos == 1 )    ///pos == 1 means ATRStop line is green    +strategy.entry(id="VWMA LE", direction = strategy.long, qty=qty1, when= rsiofVwmaVal>=30 and  close>open and close>vwmaVal and pos == 1 )    ///pos == 1 means ATRStop line is green    //vwmaVal2>vwmaVal and⋯//Exit-strategy.close(id="VWMA LE",  when= strategy.position_size>=1 and crossunder(close, xATRTrailingStop)  )+strategy.close(id="VWMA LE",  when= strategy.position_size>=1 and ta.crossunder(close, xATRTrailingStop)  )//strategy.close(id="VWMA LE",  when= strategy.position_size>=1 and close<vwmaVal and open<vwmaVal and close<open )

Clean v5

VerifiedDownload the v5 script

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

  • Line 8: input() → input.int()
  • Line 10: input() → input.int()
  • Line 11: input() → input.float()
  • Line 12: input() → input.int()
  • Line 13: input() → input.int()
  • Line 14: input() → input.int()
  • Line 36: when = rsiofVwmaVal>=30 and close>open and close>vwmaVal and pos == 1 → if block
  • Line 41: when = strategy.position_size>=1 and ta.crossunder(close, xATRTrailingStop) → if block
⋯int pos=na-vwmalength = input(33, title="VWMA Length", minval=1, maxval=365)+vwmalength = input.int(33, title="VWMA Length", minval=1, maxval=365)//vwmalength2 = input(9, title="VWAM Short Term Length", minval=1, maxval=365)-nATRPeriod = input(33, title="ATR length", minval=1, maxval=365)+nATRPeriod = input.int(33, title="ATR length", minval=1, maxval=365)-nATRMultip = input(3.5, title="ATR Multiplier")+nATRMultip = input.float(3.5, title="ATR Multiplier")-rsiofVwmaLength=input(14, title="RSI of VWMA Length")+rsiofVwmaLength=input.int(14, title="RSI of VWMA Length")-riskCapital = input(title="Risk % of capital", defval=10, minval=1)+riskCapital = input.int(title="Risk % of capital", defval=10, minval=1)-stopLoss=input(5,title="Stop Loss",minval=1)+stopLoss=input.int(5,title="Stop Loss",minval=1)vwmaVal=ta.vwma(close, vwmalength)⋯//strategy.entry(id="VWMA LE", long=true, qty=qty1, when= close >vwmaVal and open>vwmaVal and close>open and close > xATRTrailingStop and xATRTrailingStop>  vwmaVal)-strategy.entry(id="VWMA LE", direction = strategy.long, qty=qty1, when= rsiofVwmaVal>=30 and  close>open and close>vwmaVal and pos == 1 )    ///pos == 1 means ATRStop line is green    +if rsiofVwmaVal>=30 and  close>open and close>vwmaVal and pos == 1+    strategy.entry(id="VWMA LE", direction = strategy.long, qty=qty1 )    ///pos == 1 means ATRStop line is green    //vwmaVal2>vwmaVal and⋯//Exit-strategy.close(id="VWMA LE",  when= strategy.position_size>=1 and ta.crossunder(close, xATRTrailingStop)  )+if strategy.position_size>=1 and ta.crossunder(close, xATRTrailingStop)+    strategy.close(id="VWMA LE"  )//strategy.close(id="VWMA LE",  when= strategy.position_size>=1 and close<vwmaVal and open<vwmaVal and close<open )

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: 8 before, 8 after on ETHUSDT 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//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
VWMA Length33int · min 1 · max 365vwmaVal
ATR length33int · min 1 · max 365xATR
ATR Multiplier3.5floatnLoss
RSI of VWMA Length14intrsiofVwmaVal
Risk % of capital10int · min 1qty1
Stop Loss5int · min 1qty1

What it calculates

  • VWMA (vwma, ta.vwma in v5)close, VWMA Length (33)vwmaVal · line 15
  • RSI (rsi, ta.rsi in v5)vwmaVal, RSI of VWMA Length (14)rsiofVwmaVal · line 22
  • ATR (atr, ta.atr in v5)ATR length (33)xATR · line 23

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 datavwmalengthVWMA Lengthsetting · 33rsiofVwmaLengthRSI of VWMA Lengthsetting · 14high · low · closehigh · low · closeprice datanATRPeriodATR lengthsetting · 33nATRMultipATR Multipliersetting · 3.5riskCapitalRisk % of capitalsetting · 10stopLossStop Losssetting · 5openopenprice datavwmaValVWMA→ vwmaValrsiofVwmaValRSI→ rsiofVwmaValxATRATR→ xATRnLossnLossvalueqty1qty1valuexATRTrailingStopxATRTrailingStopconditionposposconditioncolor1Colourcolor1entry:VWMA LEOpen VWMA LEstrategy.entryclose:VWMA LEClose VWMA LEstrategy.closeplot:18VWMAplotplot:38ATR Trailing Stopplotbgcolor:39bgcolorbgcolor

Order rules

OrderFires whenBy defaultLine
Open VWMA LE longrsiofVwmaVal>=30 and close>open and close>vwmaVal and pos == 1On36
Close VWMA LEstrategy.position_size>=1 and crossunder(close, xATRTrailingStop)On41

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.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • 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 1D0.0%+102.5%00%—31.4%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h0.0%+5.5%00%—12.1%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+28.4%+9.8%850%1.3941.2%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+30.0%+8.4%560%7.016.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−38.4%+16.7%922%0.4658.7%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+34.0%+21.5%650%3.229.8%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+20.4%+148.3%875%1.5925.4%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+7.7%+17.1%944%1.4311.2%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

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
VWMA_withATRstops_strategy this page—v4 strategy0.0%031.4%
SuperTREX strategy by RafaelZionirsi atrv4 strategy−3.8%36.1%
[KL] RSI 14 + 10 Strategy by DojiEmojiatr rsiv4 strategy+4.2%2739.7%
MA cross strategy by Glenn234rsi atrv5 strategy−606.2%35656.0%
Mathias & Christer Timeframe RSI by mattehalenrsi atrv4 strategy−0.7%180.7%
Estrategia Larry Connors [JoseMetal] by JoseMetalrsi atrv5 strategy+2.7%242.4%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 11 msWith a workaround 1,000 bars in 44 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 (line 36) 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//strategy("", overlay=true)strategy(title="VWMA_withATRstops_strategy V2", overlay=true, pyramiding=1,     default_qty_type=strategy.percent_of_equity,  default_qty_value=20, initial_capital=10000, currency=currency.USD)  //default_qty_value=10, default_qty_type=strategy.fixed,float xATRTrailingStop=naint pos=navwmalength = input(33, title="VWMA Length", minval=1, maxval=365)//vwmalength2 = input(9, title="VWAM Short Term Length", minval=1, maxval=365)nATRPeriod = input(33, title="ATR length", minval=1, maxval=365)nATRMultip = input(3.5, title="ATR Multiplier")rsiofVwmaLength=input(14, title="RSI of VWMA Length")riskCapital = input(title="Risk % of capital", defval=10, minval=1)stopLoss=input(5,title="Stop Loss",minval=1)vwmaVal=vwma(close, vwmalength)//vwmaVal2=vwma(close, vwmalength2)//maVal=sma(close, vwmalength)plot(vwmaVal, color=color.orange, linewidth=2,  title="VWMA")//plot(vwmaVal2, color=color.blue, title="VWMA Short Term")//plot(maVal, color=color.blue, title="MA")//rsi of vwma LongtermrsiofVwmaVal=rsi(vwmaVal,rsiofVwmaLength)xATR = atr(nATRPeriod)nLoss = nATRMultip * xATRxATRTrailingStop:= iff(close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), close - nLoss), iff(close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), close + nLoss), iff(close > nz(xATRTrailingStop[1], 0), close - nLoss, close + nLoss)))pos:=   iff(close[1] < nz(xATRTrailingStop[1], 0) and close > nz(xATRTrailingStop[1], 0), 1,        iff(close[1] > nz(xATRTrailingStop[1], 0) and close < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0))) color1 = pos == -1 ? color.red: pos == 1 ? color.green : color.blue //plot(xATRTrailingStop, color=color1, title="ATR Trailing Stop")//Entry--//Echeck how many units can be purchased based on risk manage ment and stop lossqty1 = (strategy.equity  * riskCapital / 100 ) /  (close*stopLoss/100)  //check if cash is sufficient  to buy qty1  , if capital not available use the available capital onlyqty1:= (qty1 * close >= strategy.equity ) ? (strategy.equity / close) : qty1//Long Entry//strategy.entry(id="VWMA LE", long=true, qty=qty1, when= close >vwmaVal and open>vwmaVal and close>open and close > xATRTrailingStop and xATRTrailingStop>  vwmaVal)strategy.entry(id="VWMA LE", long=true, qty=qty1, when= rsiofVwmaVal>=30 and  close>open and close>vwmaVal and pos == 1 )    ///pos == 1 means ATRStop line is green    //vwmaVal2>vwmaVal andplot(strategy.position_size>=1  ? xATRTrailingStop : na, color=color1, style=plot.style_linebr, title="ATR Trailing Stop")bgcolor(strategy.position_size>=1 ? color.blue : na )//Exitstrategy.close(id="VWMA LE",  when= strategy.position_size>=1 and crossunder(close, xATRTrailingStop)  )//strategy.close(id="VWMA LE",  when= strategy.position_size>=1 and close<vwmaVal and open<vwmaVal and close<open )