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
- 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
VerifiedSame 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 )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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| VWMA Length | 33 | int · min 1 · max 365 | vwmaVal |
| ATR length | 33 | int · min 1 · max 365 | xATR |
| ATR Multiplier | 3.5 | float | nLoss |
| RSI of VWMA Length | 14 | int | rsiofVwmaVal |
| Risk % of capital | 10 | int · min 1 | qty1 |
| Stop Loss | 5 | int · min 1 | qty1 |
What it calculates
- VWMA (
vwma,ta.vwmain v5)close, VWMA Length (33)vwmaVal · line 15 - RSI (
rsi,ta.rsiin v5)vwmaVal, RSI of VWMA Length (14)rsiofVwmaVal · line 22 - ATR (
atr,ta.atrin 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open VWMA LE long | rsiofVwmaVal>=30 and close>open and close>vwmaVal and pos == 1 | On | 36 |
| Close VWMA LE | strategy.position_size>=1 and crossunder(close, xATRTrailingStop) | On | 41 |
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 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 | 0.0% | +102.5% | 0 | 0% | — | 31.4% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 12.1% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +28.4% | +9.8% | 8 | 50% | 1.39 | 41.2% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +30.0% | +8.4% | 5 | 60% | 7.01 | 6.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −38.4% | +16.7% | 9 | 22% | 0.46 | 58.7% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +34.0% | +21.5% | 6 | 50% | 3.22 | 9.8% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +20.4% | +148.3% | 8 | 75% | 1.59 | 25.4% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +7.7% | +17.1% | 9 | 44% | 1.43 | 11.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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| VWMA_withATRstops_strategy this page | — | v4 strategy | 0.0% | 0 | 31.4% |
| SuperTREX strategy by RafaelZioni | rsi atr | v4 strategy | −3.8% | 3 | 6.1% |
| [KL] RSI 14 + 10 Strategy by DojiEmoji | atr rsi | v4 strategy | +4.2% | 27 | 39.7% |
| MA cross strategy by Glenn234 | rsi atr | v5 strategy | −606.2% | 35 | 656.0% |
| Mathias & Christer Timeframe RSI by mattehalen | rsi atr | v4 strategy | −0.7% | 18 | 0.7% |
| Estrategia Larry Connors [JoseMetal] by JoseMetal | rsi atr | v5 strategy | +2.7% | 24 | 2.4% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 11 ms | With a workaround 1,000 bars in 44 ms | Not measured |
| PineTS | No 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 )