Pine Script v4 · Strategy
VWAP and RSI strategy
A Pine Script v4 strategy built on EMA (close, 200), RSI (close, 3) 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 one contract and pays no commission. 7 settings; defaults include Long EMA 200, short EMA 50 and RSI Period 3.
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 VWAP and RSI 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 VWAP and RSI strategy do on BTCUSDT 1D with default settings?
- +164.35%
- From 26 Jan 2024 to 21 Oct 2026, over 7 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can VWAP and RSI 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 VWAP and RSI strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does VWAP and RSI strategy run in Zeal Terminal?
- Yes
- It compiles in 26 ms and runs 1,000 bars in 40 ms, in the browser.
BTCUSDT · 1D · default settings
- RSI
- Buy Line
- Sell Line
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +164.35%
- $16,435.20
- Buy and hold
- +102.5%
- same period
- Closed trades
- 7
- 3 won · 4 lost
- Profitable
- 42.9%
- of closed trades
- Profit factor
- 1.70
- gross profit ÷ gross loss
- Max drawdown
- 210.92%
- −$21,092.10
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 41, 46, 50, 53. The upgraded version below moves each call inside an if block.
-
Note
Uses transp =, which v5 removed line 47
transp = on line 47. v5 folds the transparency into the colour with color.new(c, transp).
-
Note
Uses long =, which v5 renamed line 41
long = on line 41, 46. 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 ema → ta.ema, rsi → ta.rsi, vwap → ta.vwap, crossunder → ta.crossunder.
- 4 strategy calls use the when = argument (line 41, 46, 50, 53). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 7 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 24: ema → ta.ema
- Line 25: ema → ta.ema
- Line 26: rsi → ta.rsi
- Line 27: vwap → ta.vwap
- Line 41: long = true → direction = strategy.long
3 more edits
- Line 46: long = true → direction = strategy.long
- Line 47: transp = 0 → color.new(add_on_divergence and addCondition ? color.green : na, 0)
- Line 50: crossunder → ta.crossunder
⋯// © mohanee-//@version=4+//@version=5strategy(title="VWAP and RSI strategy [EEMANI] v2", overlay=false,pyramiding=2, default_qty_type=strategy.fixed, initial_capital=10000, currency=currency.USD)⋯//variables END-longEMAval= ema(close, longEMA)+longEMAval= ta.ema(close, longEMA)-shortEMAval= ema(close, shortEMA)+shortEMAval= ta.ema(close, shortEMA)-rsiVal=rsi(close,rsi1)+rsiVal=ta.rsi(close,rsi1)-vwapVal=vwap(hlc3)+vwapVal=ta.vwap(hlc3)// Drawings⋯//Entry-strategy.entry(id="VWAP_RSI LE", comment="VR LE" , long=true, when= longCondition and strategy.position_size<1 ) //and rsiDipped+strategy.entry(id="VWAP_RSI LE", comment="VR LE" , direction = strategy.long, when= longCondition and strategy.position_size<1 ) //and rsiDipped//Add⋯addCondition = add_on_divergence and barCount[1] > 1 and strategy.position_size>=1 and close<=close[barCount[1]] and rsiVal>rsiVal[barCount+1] and close>open and close>vwapVal //and open>vwapVal-strategy.entry(id="VWAP_RSI LE", comment="Add " , long=true, when= addCondition ) //and rsiDipped comment="Add " +tostring(barCount[1],"####")+strategy.entry(id="VWAP_RSI LE", comment="Add " , direction = strategy.long, when= addCondition ) //and rsiDipped comment="Add " +tostring(barCount[1],"####")-bgcolor(add_on_divergence and addCondition ? color.green : na,transp=0)+bgcolor(color.new(add_on_divergence and addCondition ? color.green : na, 0)) //Take profit Exit-strategy.close(id="VWAP_RSI LE", comment="TP Exit", when=crossunder(rsiVal,90) )+strategy.close(id="VWAP_RSI LE", comment="TP Exit", when=ta.crossunder(rsiVal,90) )//stoploss⋯Same 7 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 16: input() → input.int()
- Line 17: input() → input.int()
- Line 18: input() → input.int()
- Line 19: input() → input.int()
- Line 20: input() → input.int()
- Line 21: input() → input.bool()
5 more edits
- Line 22: input() → input.int()
- Line 41: when = longCondition and strategy.position_size<1 → if block
- Line 46: when = addCondition → if block
- Line 50: when = ta.crossunder(rsiVal,90) → if block
- Line 53: when = close < stopLossVal → if block
⋯// variables BEGIN-longEMA = input(200, title="Long EMA", minval=1)+longEMA = input.int(200, title="Long EMA", minval=1)-shortEMA = input(50, title="short EMA", minval=1)+shortEMA = input.int(50, title="short EMA", minval=1)-rsi1 = input(3,title="RSI Period", minval=1)+rsi1 = input.int(3,title="RSI Period", minval=1)-rsi_buy_line = input(15,title="RSI Buy Line", minval=5)+rsi_buy_line = input.int(15,title="RSI Buy Line", minval=5)-rsi_sell_line = input(90,title="RSI Sell Line", minval=50)+rsi_sell_line = input.int(90,title="RSI Sell Line", minval=50)-add_on_divergence=input(true,title="Add on RSI divergence")+add_on_divergence=input.bool(true,title="Add on RSI divergence")-stopLoss = input(title="Stop Loss%", defval=5, minval=1)+stopLoss = input.int(title="Stop Loss%", defval=5, minval=1)//variables END⋯//Entry-strategy.entry(id="VWAP_RSI LE", comment="VR LE" , direction = strategy.long, when= longCondition and strategy.position_size<1 ) //and rsiDipped+if longCondition and strategy.position_size<1+ strategy.entry(id="VWAP_RSI LE", comment="VR LE" , direction = strategy.long ) //and rsiDipped//Add⋯addCondition = add_on_divergence and barCount[1] > 1 and strategy.position_size>=1 and close<=close[barCount[1]] and rsiVal>rsiVal[barCount+1] and close>open and close>vwapVal //and open>vwapVal-strategy.entry(id="VWAP_RSI LE", comment="Add " , direction = strategy.long, when= addCondition ) //and rsiDipped comment="Add " +tostring(barCount[1],"####")+if addCondition+ strategy.entry(id="VWAP_RSI LE", comment="Add " , direction = strategy.long ) //and rsiDipped comment="Add " +tostring(barCount[1],"####")bgcolor(color.new(add_on_divergence and addCondition ? color.green : na, 0))⋯//Take profit Exit-strategy.close(id="VWAP_RSI LE", comment="TP Exit", when=ta.crossunder(rsiVal,90) )+if ta.crossunder(rsiVal,90)+ strategy.close(id="VWAP_RSI LE", comment="TP Exit" )//stoplossstopLossVal = strategy.position_avg_price - (strategy.position_avg_price*stopLoss*0.01) -strategy.close(id="VWAP_RSI LE", comment="SL Exit", when= close < stopLossVal)+if close < stopLossVal+ strategy.close(id="VWAP_RSI LE", comment="SL Exit")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: 7 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=6strategy(title="VWAP and RSI strategy [EEMANI] v2", overlay=false,pyramiding=2, default_qty_type=strategy.fixed, initial_capital=10000, currency=currency.USD)⋯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 |
|---|---|---|---|
| Long EMA | 200 | int · min 1 | longEMAval |
| short EMA | 50 | int · min 1 | shortEMAval |
| RSI Period | 3 | int · min 1 | rsiVal |
| RSI Buy Line | 15 | int · min 5 | rsiDipped Buy Line |
| RSI Sell Line | 90 | int · min 50 | Sell Line |
| Add on RSI divergence | true | bool | addCondition bgcolor |
| Stop Loss% | 5 | int · min 1 | stopLossVal |
What it calculates
- EMA (
ema,ta.emain v5)close, Long EMA (200)longEMAval · line 24 - EMA (
ema,ta.emain v5)close, short EMA (50)shortEMAval · line 25 - RSI (
rsi,ta.rsiin v5)close, RSI Period (3)rsiVal · line 26 - VWAP (
vwap,ta.vwapin v5)hlc3vwapVal · line 27
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 VWAP_RSI LE long | longCondition and strategy.position_size<1 | On | 41 |
| Open VWAP_RSI LE long | addConditionadd_on_divergence and barCount[1] > 1 and strategy.position_size>=1 and close<=close[barCount[1]] and rsiVal>rsiVal[barCount+1] and close>open and close>vwapVal | On | 46 |
| Close VWAP_RSI LE | crossunder(rsiVal,90) | On | 50 |
| Close VWAP_RSI LE | close < stopLossVal | On | 53 |
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 | +164.4% | +102.5% | 7 | 43% | 1.70 | 210.9% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +245.6% | +5.5% | 18 | 83% | 21.47 | 26.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.6% | +9.8% | 3 | 33% | 1.18 | 4.4% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +6.1% | +8.4% | 15 | 87% | 4.76 | 1.6% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −0.3% | +16.7% | 4 | 25% | 0.25 | 0.7% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −0.1% | +21.5% | 11 | 36% | 0.58 | 0.2% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.1% | +148.3% | 6 | 50% | 1.04 | 1.2% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +1.4% | +17.1% | 14 | 71% | 2.56 | 1.1% | 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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 2 | 100% | $25,369.70 |
| Sideways market | 4 | 0% | −$23,520.60 |
| Falling market | 1 | 100% | $14,586.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
1,820,310.0%
The 95th percentile of the worst drawdown when the same 7 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 161.4% to 1,820,310.0%; the tick is what actually happened, 1,038.5%. Order luck alone moves it this much.
All 7 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 10 Feb 2025 96,462.80 | 25 Feb 2025 91,552.90 | 15 | −$4,909.87 |
| long | 20 Feb 2025 96,644.40 | 25 Feb 2025 91,552.90 | 5 | −$5,091.49 |
| long | 5 Mar 2025 87,282.00 | 10 Mar 2025 80,734.50 | 5 | −$6,547.50 |
| long | 8 Apr 2025 79,163.20 | 28 Apr 2025 93,749.30 | 20 | $14,586.00 |
| long | 3 Jun 2025 105,858.00 | 16 Jul 2025 117,758.00 | 43 | $11,900.10 |
| long | 7 Jun 2025 104,288.00 | 16 Jul 2025 117,758.00 | 39 | $13,469.70 |
| long | 14 Oct 2025 115,166.00 | 17 Oct 2025 108,194.00 | 3 | −$6,971.73 |
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 |
|---|---|---|---|---|---|
| VWAP and RSI strategy this page | — | v4 strategy | +164.4% | 7 | 210.9% |
| Power Zonessssss by liuen | vwap ema rsi | v5 strategy | +2.5% | 4 | 5.1% |
| VWAP_X_EMA by justvishu91 | vwap ema | v4 strategy | No trades on this market | ||
| 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% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 26 ms | With a workaround 1,000 bars in 40 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 (lines 41, 46) 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="VWAP and RSI strategy [EEMANI] v2", overlay=false,pyramiding=2, default_qty_type=strategy.fixed, initial_capital=10000, currency=currency.USD)//This strategy combines VWAP and RSI indicators//BUY RULE//1. EMA50 > EMA 200//2. if current close > vwap session value and close>open //3. check if RSI3 is dipped below 10 for any of last 10 candles//EXIT RULE//1. RSI3 crossing down 90 level//STOP LOSS EXIT//1. As configured --- default is set to 5%int barCount = 0// variables BEGINlongEMA = input(200, title="Long EMA", minval=1)shortEMA = input(50, title="short EMA", minval=1)rsi1 = input(3,title="RSI Period", minval=1)rsi_buy_line = input(15,title="RSI Buy Line", minval=5)rsi_sell_line = input(90,title="RSI Sell Line", minval=50)add_on_divergence=input(true,title="Add on RSI divergence")stopLoss = input(title="Stop Loss%", defval=5, minval=1)//variables ENDlongEMAval= ema(close, longEMA)shortEMAval= ema(close, shortEMA)rsiVal=rsi(close,rsi1)vwapVal=vwap(hlc3)// Drawingsplot_rsi = plot(rsiVal, title="RSI", color=color.purple, linewidth=1)//plot_fill = plot(0, color=color.green, editable=false)//fill(plot_rsi, plot_fill, title="Oscillator Fill", color=color.blue, transp=75) hline(rsi_buy_line, color=color.green, title="Buy Line", linewidth=2, linestyle=hline.style_dashed)hline(rsi_sell_line, color=color.purple, title="Sell Line", linewidth=2, linestyle=hline.style_dashed)//plot(value_ma, title="MA", color=color_ma, linewidth=2)rsiDipped=falsefor i = 1 to 10 rsiDipped := rsiDipped or rsiVal[i]<rsi_buy_line//rsiDipped = rsiVal[1]<rsi_buy_line or rsiVal[2]<rsi_buy_line or rsiVal[3]<rsi_buy_line or rsiVal[4]<rsi_buy_line or rsiVal[5]<rsi_buy_line or rsiVal[6]<rsi_buy_line or rsiVal[7]<rsi_buy_line or rsiVal[8]<rsi_buy_line or rsiVal[9]<rsi_buy_line or rsiVal[10]<rsi_buy_line longCondition= shortEMAval > longEMAval and close>open and close>vwapVal and open>vwapVal and rsiDipped//Entrystrategy.entry(id="VWAP_RSI LE", comment="VR LE" , long=true, when= longCondition and strategy.position_size<1 ) //and rsiDipped//Add//barCount:=nz(barssince(longCondition),1)barCount := strategy.position_size>0 ? (barCount[1]+1) : 0addCondition = add_on_divergence and barCount[1] > 1 and strategy.position_size>=1 and close<=close[barCount[1]] and rsiVal>rsiVal[barCount+1] and close>open and close>vwapVal //and open>vwapValstrategy.entry(id="VWAP_RSI LE", comment="Add " , long=true, when= addCondition ) //and rsiDipped comment="Add " +tostring(barCount[1],"####")bgcolor(add_on_divergence and addCondition ? color.green : na,transp=0) //Take profit Exitstrategy.close(id="VWAP_RSI LE", comment="TP Exit", when=crossunder(rsiVal,90) )//stoplossstopLossVal = strategy.position_avg_price - (strategy.position_avg_price*stopLoss*0.01) strategy.close(id="VWAP_RSI LE", comment="SL Exit", when= close < stopLossVal)