Pine Script v4 · Strategy
RSI of VWAP
A Pine Script v4 strategy built on RSI (vwap, 14) and EMA (close, 200). It has 4 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 RSI Length 14, RSI Buy Line 70 and RSI Exit Line 90.
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 RSI of VWAP repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did RSI of VWAP 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 BTCUSDT 4h it did trade; that row of the markets table below has its figures. A backtest, not investment advice.
- Can RSI of VWAP 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 RSI of VWAP use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does RSI of VWAP run in Zeal Terminal?
- Yes
- It compiles in 18 ms and runs 1,000 bars in 45 ms, in the browser.
BTCUSDT · 1D · default settings
- EMA 200
- VWAP
- 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
- 12.12%
- −$1,211.76
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.
-
Likely bug
crossover(vwapRsi, 99) ignores the settings line 30
Line 30 hard-codes 99 where line 23 uses “RSI Buy Line”. Changing those settings moves one band but not this one.
crossover(vwapRsi,99)crossover(vwapRsi, buyLine) -
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 23, 30, 32, 34. The upgraded version below moves each call inside an if block.
-
Note
Uses transp =, which v5 removed line 14
transp = on line 14, 15, 28. v5 folds the transparency into the colour with color.new(c, transp).
-
Note
Uses long =, which v5 renamed line 23
long = on line 23. 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 rsi → ta.rsi, ema → ta.ema, crossover → ta.crossover, tostring → str.tostring, crossunder → ta.crossunder.
- 4 strategy calls use the when = argument (line 23, 30, 32, 34). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 3 trades and the same P&L on BTCUSDT 4h, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 11: vwap → ta.vwap
- Line 12: rsi → ta.rsi
- Line 12: vwap → ta.vwap
- Line 13: ema → ta.ema
- Line 14: transp = 25 → color.new(color.orange, 25)
9 more edits
- Line 15: transp = 25 → color.new(color.purple, 25)
- Line 23: long = true → direction = strategy.long
- Line 23: crossover → ta.crossover
- Line 28: transp = 80 → color.new(strategy.position_size>=1?color.blue:na, 80)
- Line 30: tostring → str.tostring
- Line 30: crossover → ta.crossover
- Line 32: tostring → str.tostring
- Line 32: crossunder → ta.crossunder
- Line 34: tostring → str.tostring
⋯// © mohanee-//@version=4+//@version=5strategy(title="RSI of VWAP", 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,⋯partialExit=input(true,title="Allow Partial exit / take profits")-myVwap=vwap+myVwap=ta.vwap-vwapRsi=rsi(vwap,rsiLength)+vwapRsi=ta.rsi(ta.vwap,rsiLength)-ema200=ema(close,200)+ema200=ta.ema(close,200)-plot(ema200, title="EMA 200", color=color.orange, transp=25)+plot(ema200, title="EMA 200", color=color.new(color.orange, 25))-plot(myVwap, title="VWAP", color=color.purple, transp=25)+plot(myVwap, title="VWAP", color=color.new(color.purple, 25))//plot(close)⋯//more than 80%-strategy.entry(id="LE", comment="Entry", long=true, qty=qty1, when=crossover(vwapRsi,buyLine) and close>ema200 )+strategy.entry(id="LE", comment="Entry", direction = strategy.long, qty=qty1, when=ta.crossover(vwapRsi,buyLine) and close>ema200 )//stoploss⋯plot(strategy.position_size>=1 ? stopLossVal : na, color = color.purple , style=plot.style_linebr, linewidth = 2, title = "stop loss")-bgcolor(strategy.position_size>=1?color.blue:na, transp=80)+bgcolor(color.new(strategy.position_size>=1?color.blue:na, 80))if(partialExit==true)- strategy.close(id="LE",comment="TP points="+tostring(close - strategy.position_avg_price, "####.##"),qty=strategy.position_size/3, when=crossover(vwapRsi,99) ) //and close>ema200+ strategy.close(id="LE",comment="TP points="+str.tostring(close - strategy.position_avg_price, "####.##"),qty=strategy.position_size/3, when=ta.crossover(vwapRsi,99) ) //and close>ema200 -strategy.close_all(comment="Exit All points="+tostring(close - strategy.position_avg_price, "####.##"), when=crossunder(vwapRsi,exitLine) ) //and close>ema200+strategy.close_all(comment="Exit All points="+str.tostring(close - strategy.position_avg_price, "####.##"), when=ta.crossunder(vwapRsi,exitLine) ) //and close>ema200//close all on stop loss-strategy.close_all(comment="Exit points="+tostring(close - strategy.position_avg_price, "####.##"), when=close<stopLossVal ) //and close>ema200+strategy.close_all(comment="Exit points="+str.tostring(close - strategy.position_avg_price, "####.##"), when=close<stopLossVal ) //and close>ema200Same 3 trades and the same P&L on BTCUSDT 4h, 1,000 bars, in Zeal Terminal's engine.
- Line 5: input() → input.int()
- Line 6: input() → input.int()
- Line 7: input() → input.int()
- Line 8: input() → input.int()
- Line 9: input() → input.int()
- Line 10: input() → input.bool()
4 more edits
- Line 23: when = ta.crossover(vwapRsi,buyLine) and close>ema200 → if block
- Line 30: when = ta.crossover(vwapRsi,99) → if block
- Line 32: when = ta.crossunder(vwapRsi,exitLine) → if block
- Line 34: when = close<stopLossVal → if block
⋯strategy(title="RSI of VWAP", 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,-rsiLength=input(14,title="RSI Length", minval=1, maxval=50)+rsiLength=input.int(14,title="RSI Length", minval=1, maxval=50)-buyLine=input(70,title="RSI Buy Line", minval=30, maxval=100)+buyLine=input.int(70,title="RSI Buy Line", minval=30, maxval=100)-exitLine=input(90,title="RSI Exit Line", minval=0, maxval=100)+exitLine=input.int(90,title="RSI Exit Line", minval=0, maxval=100)-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)-partialExit=input(true,title="Allow Partial exit / take profits")+partialExit=input.bool(true,title="Allow Partial exit / take profits")myVwap=ta.vwap⋯//more than 80%-strategy.entry(id="LE", comment="Entry", direction = strategy.long, qty=qty1, when=ta.crossover(vwapRsi,buyLine) and close>ema200 )+if ta.crossover(vwapRsi,buyLine) and close>ema200+ strategy.entry(id="LE", comment="Entry", direction = strategy.long, qty=qty1 )//stoploss⋯if(partialExit==true)- strategy.close(id="LE",comment="TP points="+str.tostring(close - strategy.position_avg_price, "####.##"),qty=strategy.position_size/3, when=ta.crossover(vwapRsi,99) ) //and close>ema200+ if ta.crossover(vwapRsi,99)+ strategy.close(id="LE",comment="TP points="+str.tostring(close - strategy.position_avg_price, "####.##"),qty=strategy.position_size/3 ) //and close>ema200 -strategy.close_all(comment="Exit All points="+str.tostring(close - strategy.position_avg_price, "####.##"), when=ta.crossunder(vwapRsi,exitLine) ) //and close>ema200+if ta.crossunder(vwapRsi,exitLine)+ strategy.close_all(comment="Exit All points="+str.tostring(close - strategy.position_avg_price, "####.##") ) //and close>ema200//close all on stop loss-strategy.close_all(comment="Exit points="+str.tostring(close - strategy.position_avg_price, "####.##"), when=close<stopLossVal ) //and close>ema200+if close<stopLossVal+ strategy.close_all(comment="Exit points="+str.tostring(close - strategy.position_avg_price, "####.##") ) //and close>ema200Does it run in Pine Script v6?
Yes
Same 3 trades and the same P&L on BTCUSDT 4h, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.
⋯// © mohanee-//@version=5+//@version=6strategy(title="RSI of VWAP", 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,⋯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 |
|---|---|---|---|
| RSI Length | 14 | int · min 1 · max 50 | vwapRsi |
| RSI Buy Line | 70 | int · min 30 · max 100 | entry LE |
| RSI Exit Line | 90 | int · min 0 · max 100 | close_all |
| Risk % of capital | 10 | int · min 1 | qty1 |
| Stop Loss | 5 | int · min 1 | qty1 stopLossVal |
| Allow Partial exit / take profits | true | bool | close LE line 29 |
What it calculates
- RSI (
rsi,ta.rsiin v5)vwap, RSI Length (14)vwapRsi · line 12 - EMA (
ema,ta.emain v5)close, 200ema200 · line 13
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 LE long | crossover(vwapRsi,buyLine) and close>ema200 | On | 23 |
| Close LE | crossover(vwapRsi,99) | On | 30 |
| Close | crossunder(vwapRsi,exitLine) | On | 32 |
| Close | close<stopLossVal | On | 34 |
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% | — | 12.1% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +27.8% | +5.5% | 3 | 100% | — | 6.7% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −21.6% | +9.8% | 3 | 0% | 0.00 | 28.3% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +37.0% | +8.4% | 2 | 100% | — | 4.9% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −45.8% | +16.7% | 8 | 0% | 0.00 | 47.2% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +28.5% | +21.5% | 4 | 75% | 5.97 | 7.2% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −31.0% | +148.3% | 5 | 0% | 0.00 | 31.7% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +18.5% | +17.1% | 3 | 67% | 3.90 | 5.7% | 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 |
|---|---|---|---|---|---|
| RSI of VWAP this page | — | v4 strategy | 0.0% | 0 | 12.1% |
| RSI Cross [xaurr] by livetrend | rsi ema | v4 strategy | +24.4% | 53 | 35.3% |
| Bitpanda Coinrule Template by joshuajcoop01 | rsi ema | v5 strategy | −2.8% | 4 | 4.6% |
| RSI with Slow and Fast MA Crossing Strategy (by Coinrule) by Coinrule | rsi ema | v5 strategy | −2.8% | 4 | 4.6% |
| EMA SCALPEUR + RSi - SHORT by YukalMoon | rsi ema | v5 strategy | No trades on this market | ||
| BTC Sentiment analysis RSI 2xEMA by exlux99 | rsi ema | v4 strategy | No trades on this market | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 18 ms | With a workaround 1,000 bars in 45 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 23) 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=4strategy(title="RSI of VWAP", 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,rsiLength=input(14,title="RSI Length", minval=1, maxval=50)buyLine=input(70,title="RSI Buy Line", minval=30, maxval=100)exitLine=input(90,title="RSI Exit Line", minval=0, maxval=100)riskCapital = input(title="Risk % of capital", defval=10, minval=1)stopLoss=input(5,title="Stop Loss",minval=1)partialExit=input(true,title="Allow Partial exit / take profits")myVwap=vwapvwapRsi=rsi(vwap,rsiLength)ema200=ema(close,200)plot(ema200, title="EMA 200", color=color.orange, transp=25)plot(myVwap, title="VWAP", color=color.purple, transp=25)//plot(close)//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//more than 80%strategy.entry(id="LE", comment="Entry", long=true, qty=qty1, when=crossover(vwapRsi,buyLine) and close>ema200 )//stoplossstopLossVal= strategy.position_size>=1 ? (strategy.position_avg_price * (1-(stopLoss*0.01) )) : 0.00//draw initil stop lossplot(strategy.position_size>=1 ? stopLossVal : na, color = color.purple , style=plot.style_linebr, linewidth = 2, title = "stop loss")bgcolor(strategy.position_size>=1?color.blue:na, transp=80)if(partialExit==true) strategy.close(id="LE",comment="TP points="+tostring(close - strategy.position_avg_price, "####.##"),qty=strategy.position_size/3, when=crossover(vwapRsi,99) ) //and close>ema200 strategy.close_all(comment="Exit All points="+tostring(close - strategy.position_avg_price, "####.##"), when=crossunder(vwapRsi,exitLine) ) //and close>ema200//close all on stop lossstrategy.close_all(comment="Exit points="+tostring(close - strategy.position_avg_price, "####.##"), when=close<stopLossVal ) //and close>ema200