Pine Script v4 · Strategy
RSI V Pattern strategy
A Pine Script v4 strategy built on RSI (close, 5), EMA (close, 50) and Crossover (myRsi, 70). 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 10% of equity and pays no commission. 3 settings; defaults include RSI Period 5, Buy at RSI 30 and Stop Loss % 8.
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 V Pattern 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 RSI V Pattern strategy do on BTCUSDT 1D with default settings?
- +1.25%
- From 26 Jan 2024 to 21 Oct 2026, over 31 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can RSI V Pattern 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 RSI V Pattern strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does RSI V Pattern strategy run in Zeal Terminal?
- Yes
- It compiles in 18 ms and runs 1,000 bars in 47 ms, in the browser.
BTCUSDT · 1D · default settings
- RSI
- Middle Line
- Overbought
- Oversold
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +1.25%
- $124.79
- Buy and hold
- +102.5%
- same period
- Closed trades
- 31
- 22 won · 9 lost
- Profitable
- 71.0%
- of closed trades
- Profit factor
- 1.21
- gross profit ÷ gross loss
- Max drawdown
- 3.30%
- −$330.20
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(myRsi, 70) ignores the settings line 42
Line 42 hard-codes 70 where line 21 uses “Buy at RSI ”. Changing those settings moves one band but not this one.
crossover(myRsi,70)crossover(myRsi, buyRsiEntry) -
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 34, 66, 68, 74. The upgraded version below moves each call inside an if block.
-
Note
Uses transp =, which v5 removed line 51
transp = on line 51, 52. v5 folds the transparency into the colour with color.new(c, transp).
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, crossunder → ta.crossunder.
- 4 strategy calls use the when = argument (line 34, 66, 68, 74). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 31 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 13: rsi → ta.rsi
- Line 14: ema → ta.ema
- Line 15: ema → ta.ema
- Line 19: ema → ta.ema
- Line 19: ema → ta.ema
9 more edits
- Line 21: ema → ta.ema
- Line 21: ema → ta.ema
- Line 21: crossover → ta.crossover
- Line 40: crossunder → ta.crossunder
- Line 42: crossover → ta.crossover
- Line 51: transp = 90 → color.new(#9915FF, 90)
- Line 52: transp = 0 → color.new(color.purple, 0)
- Line 66: crossunder → ta.crossunder
- Line 68: crossunder → ta.crossunder
⋯// © mohanee-//@version=4+//@version=5//strategy("RSI V Pattern", overlay=true)⋯stopLoss = input(title="Stop Loss %", minval=1, defval=8)-myRsi = rsi(close,len)+myRsi = ta.rsi(close,len)-longEmaVal=ema(close,50)+longEmaVal=ta.ema(close,50)-shortEmaVal=ema(close,20)+shortEmaVal=ta.ema(close,20)//plot emas ⋯//plot(shortEmaVal, title="Short EMA" ,linewidth=2, color=color.green, trackprice=true)-isEma20AboveEma50=ema(close,20)>ema(close,50) ? true : false +isEma20AboveEma50=ta.ema(close,20)>ta.ema(close,50) ? true : false //V Pattern-longCondition = ema(close,20)>ema(close,50) and (low[1]<low[2] and low[1]<low[3]) and (myRsi>myRsi[1] and myRsi>myRsi[2] ) and crossover(myRsi,buyRsiEntry) // ( and myRsi<60)+longCondition = ta.ema(close,20)>ta.ema(close,50) and (low[1]<low[2] and low[1]<low[3]) and (myRsi>myRsi[1] and myRsi>myRsi[2] ) and ta.crossover(myRsi,buyRsiEntry) // ( and myRsi<60)patternText=" V "⋯//at RSI75 move the stopLoss to entry price-moveStopLossUp=strategy.position_size>0 and crossunder(myRsi,70)+moveStopLossUp=strategy.position_size>0 and ta.crossunder(myRsi,70)barcolor(moveStopLossUp?color.blue:na)-stopLossValue:=crossover(myRsi,70) ? strategy.position_avg_price:stopLossValue+stopLossValue:=ta.crossover(myRsi,70) ? strategy.position_avg_price:stopLossValue//stopLossValue:=moveStopLossUp?strategy.position_avg_price:stopLossValue⋯osLevel = hline(25, title="Oversold", linestyle=hline.style_dotted)-fill(obLevel, osLevel, title="Background", color=#9915FF, transp=90)+fill(obLevel, osLevel, title="Background", color=color.new(#9915FF, 90))plotshape(⋯ location=location.absolute,- color=color.purple,+ color=color.new(color.purple, 0),- textcolor=color.yellow,- transp=0+ textcolor=color.yellow ) ⋯//when RSI crossing down 70 , close 1/2 position and move stop loss to average entry price-strategy.close("RSI_V_LE", qty=strategy.position_size*1/2, when=strategy.position_size>0 and crossunder(myRsi,70))+strategy.close("RSI_V_LE", qty=strategy.position_size*1/2, when=strategy.position_size>0 and ta.crossunder(myRsi,70))//when RSI reaches high reading 90 and crossing down close 3/4 position-strategy.close("RSI_V_LE", qty=strategy.position_size*3/4, when=strategy.position_size>0 and crossunder(myRsi,90))+strategy.close("RSI_V_LE", qty=strategy.position_size*3/4, when=strategy.position_size>0 and ta.crossunder(myRsi,90))//close everything when Rsi goes down below to 10 or stoploss hit ⋯Same 31 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 10: input() → input.int()
- Line 11: input() → input.int()
- Line 12: input() → input.int()
- Line 34: when = longCondition → if block
- Line 65: when = strategy.position_size>0 and ta.crossunder(myRsi,70) → if block
- Line 67: when = strategy.position_size>0 and ta.crossunder(myRsi,90) → if block
- Line 73: when = longCloseCondition → if block
⋯//RSI V pattern should occur from below 30 -len = input(title="RSI Period", minval=1, defval=5)+len = input.int(title="RSI Period", minval=1, defval=5)-buyRsiEntry = input(title="Buy at RSI ", minval=5, defval=30, maxval=60)+buyRsiEntry = input.int(title="Buy at RSI ", minval=5, defval=30, maxval=60)-stopLoss = input(title="Stop Loss %", minval=1, defval=8)+stopLoss = input.int(title="Stop Loss %", minval=1, defval=8)myRsi = ta.rsi(close,len)⋯barcolor(longCondition?color.yellow:na)-strategy.entry("RSI_V_LE", strategy.long, when=longCondition )+if longCondition+ strategy.entry("RSI_V_LE", strategy.long )//stoploss value at 10%⋯//when RSI crossing down 70 , close 1/2 position and move stop loss to average entry price-strategy.close("RSI_V_LE", qty=strategy.position_size*1/2, when=strategy.position_size>0 and ta.crossunder(myRsi,70))+if strategy.position_size>0 and ta.crossunder(myRsi,70)+ strategy.close("RSI_V_LE", qty=strategy.position_size*1/2)//when RSI reaches high reading 90 and crossing down close 3/4 position-strategy.close("RSI_V_LE", qty=strategy.position_size*3/4, when=strategy.position_size>0 and ta.crossunder(myRsi,90))+if strategy.position_size>0 and ta.crossunder(myRsi,90)+ strategy.close("RSI_V_LE", qty=strategy.position_size*3/4)//close everything when Rsi goes down below to 10 or stoploss hit ⋯//crossunder(myRsi,10) or close<stopLossValue-strategy.close("RSI_V_LE", qty=strategy.position_size,when=longCloseCondition )+if longCloseCondition+ strategy.close("RSI_V_LE", qty=strategy.position_size )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: 31 before, 25 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//strategy("RSI V Pattern", 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 |
|---|---|---|---|
| RSI Period | 5 | int · min 1 | myRsi |
| Buy at RSI | 30 | int · min 5 · max 60 | longCondition |
| Stop Loss % | 8 | int · min 1 | stopLossValue |
What it calculates
- RSI (
rsi,ta.rsiin v5)close, RSI Period (5)myRsi · line 13 - EMA (
ema,ta.emain v5)close, 50longEmaVal · line 14 - EMA (
ema,ta.emain v5)close, 20shortEmaVal · line 15 - EMA (
ema,ta.emain v5)close, 20isEma20AboveEma50 · line 19 - Crossover (
crossover,ta.crossoverin v5)myRsi, 70stopLossValue · line 36
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 RSI_V_LE long | longConditionema(close,20)>ema(close,50) and (low[1]<low[2] and low[1]<low[3]) and (myRsi>myRsi[1] and myRsi>myRsi[2] ) and crossover(myRsi,buyRsiEntry) | On | 34 |
| Close RSI_V_LE | strategy.position_size>0 and crossunder(myRsi,70) | On | 66 |
| Close RSI_V_LE | strategy.position_size>0 and crossunder(myRsi,90) | On | 68 |
| Close RSI_V_LE | longCloseConditionclose<stopLossValue | On | 74 |
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.
- 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 timingprocess_orders_on_close = true: orders fill at the signal bar's close.
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 | +1.2% | +102.5% | 31 | 71% | 1.21 | 3.3% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +0.5% | +5.5% | 25 | 76% | 1.63 | 0.5% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +3.4% | +9.8% | 18 | 56% | 1.56 | 4.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +1.5% | +8.4% | 42 | 93% | 22.03 | 0.3% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.3% | +16.7% | 15 | 53% | 1.06 | 2.6% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +1.8% | +21.5% | 47 | 94% | 8.36 | 1.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.1% | +148.3% | 32 | 84% | 0.99 | 4.3% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +2.1% | +17.1% | 43 | 84% | 2.42 | 1.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 19 | 63% | −$141.21 |
| Sideways market | 12 | 83% | $266.00 |
| Falling market | 0 | — | $0.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
4.1%
The 95th percentile of the worst drawdown when the same 31 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 1.6% to 4.1%; the tick is what actually happened, 2.6%. Order luck alone moves it this much.
All 31 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 20 Mar 2024 67,840.50 | 9 Apr 2024 69,146.00 | 20 | $9.62 |
| long | 20 Mar 2024 67,840.50 | 1 May 2024 58,365.00 | 42 | −$69.84 |
| long | 14 Apr 2024 65,661.80 | 1 May 2024 58,365.00 | 17 | −$111.06 |
| long | 18 Apr 2024 63,470.10 | 1 May 2024 58,365.00 | 13 | −$79.98 |
| long | 4 Oct 2024 62,086.00 | 21 Oct 2024 67,377.50 | 17 | $82.82 |
| long | 4 Oct 2024 62,086.00 | 31 Oct 2024 70,292.00 | 27 | $0.42 |
| long | 11 Oct 2024 62,540.00 | 31 Oct 2024 70,292.00 | 20 | $60.26 |
| long | 11 Oct 2024 62,540.00 | 14 Nov 2024 87,325.60 | 34 | $145.47 |
| long | 11 Oct 2024 62,540.00 | 25 Nov 2024 93,010.00 | 45 | $29.80 |
| long | 11 Oct 2024 62,540.00 | 9 Dec 2024 97,276.50 | 59 | $16.99 |
| long | 11 Oct 2024 62,540.00 | 18 Dec 2024 100,204.00 | 68 | $9.21 |
| long | 11 Oct 2024 62,540.00 | 7 Jan 2025 96,954.60 | 88 | $8.42 |
| long | 24 Dec 2024 98,663.60 | 7 Jan 2025 96,954.60 | 14 | −$17.50 |
| long | 31 Dec 2024 93,576.00 | 7 Jan 2025 96,954.60 | 7 | $0.43 |
| long | 31 Dec 2024 93,576.00 | 19 Jan 2025 101,332.00 | 19 | $82.30 |
| long | 10 Jan 2025 94,726.10 | 19 Jan 2025 101,332.00 | 9 | $0.16 |
| long | 10 Jan 2025 94,726.10 | 22 Jan 2025 103,707.00 | 12 | $47.76 |
| long | 10 Jan 2025 94,726.10 | 25 Feb 2025 88,680.40 | 46 | −$32.15 |
| long | 3 Feb 2025 101,329.00 | 25 Feb 2025 88,680.40 | 22 | −$127.95 |
| long | 6 Jun 2025 104,288.00 | 11 Jun 2025 108,645.00 | 5 | $21.00 |
| long | 6 Jun 2025 104,288.00 | 30 Jun 2025 107,147.00 | 24 | $13.78 |
| long | 23 Jun 2025 105,334.00 | 30 Jun 2025 107,147.00 | 7 | $4.30 |
| long | 23 Jun 2025 105,334.00 | 15 Jul 2025 117,758.00 | 22 | $44.70 |
| long | 23 Jun 2025 105,334.00 | 15 Jul 2025 117,758.00 | 22 | $44.70 |
| long | 3 Aug 2025 114,209.00 | 11 Aug 2025 118,686.00 | 8 | $19.96 |
| long | 3 Aug 2025 114,209.00 | 14 Aug 2025 118,295.00 | 11 | $9.11 |
| long | 3 Aug 2025 114,209.00 | 10 Sep 2025 113,960.00 | 38 | −$0.55 |
| long | 22 Aug 2025 116,936.00 | 10 Sep 2025 113,960.00 | 19 | −$26.01 |
| long | 24 Sep 2025 113,307.00 | 7 Oct 2025 121,333.00 | 13 | $36.08 |
| long | 24 Sep 2025 113,307.00 | 7 Oct 2025 121,333.00 | 13 | $36.08 |
| long | 23 May 2026 76,752.00 | 2 Jun 2026 66,760.80 | 10 | −$133.54 |
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 V Pattern strategy this page | — | v4 strategy | +1.2% | 31 | 3.3% |
| 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% |
| RSI of VWAP by mohanee | rsi ema | v4 strategy | No trades on this market | ||
| EMA SCALPEUR + RSi - SHORT by YukalMoon | rsi ema | v5 strategy | No trades on this market | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 18 ms | Yes 1,000 bars in 47 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
“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("RSI V Pattern", overlay=true)strategy(title="RSI V Pattern", overlay=false, pyramiding=3, default_qty_type=strategy.percent_of_equity , default_qty_value=10, initial_capital=10000, currency=currency.USD,process_orders_on_close=true)//Strategy Rules//ema20 is above ema50 --- candles are colored green on the chart//RSI value sharply coming up which makes a V shape , colored in yellow on the chart//RSI V pattern should occur from below 30 len = input(title="RSI Period", minval=1, defval=5)buyRsiEntry = input(title="Buy at RSI ", minval=5, defval=30, maxval=60)stopLoss = input(title="Stop Loss %", minval=1, defval=8)myRsi = rsi(close,len)longEmaVal=ema(close,50)shortEmaVal=ema(close,20)//plot emas //plot(longEmaVal, title="Long EMA" ,linewidth=2, color=color.orange, trackprice=true)//plot(shortEmaVal, title="Short EMA" ,linewidth=2, color=color.green, trackprice=true)isEma20AboveEma50=ema(close,20)>ema(close,50) ? true : false //V PatternlongCondition = ema(close,20)>ema(close,50) and (low[1]<low[2] and low[1]<low[3]) and (myRsi>myRsi[1] and myRsi>myRsi[2] ) and crossover(myRsi,buyRsiEntry) // ( and myRsi<60)patternText=" V "//W Pattern//longCondition = isEma20AboveEma50 and ( low[1]<low[4] and (low[1]<low[2] or low[1]<low[3])) and (myRsi[1]<65 and myRsi[3]<65 and myRsi[2]>myRsi[3] and myRsi[2]>myRsi[1] and myRsi[1]>=myRsi[3] and myRsi>myRsi[1] and myRsi>30) //longCondition = isEma20AboveEma50 and ( low[1]<low[4] or low[1]<low[3] ) and (myRsi[2]>myRsi[3] and myRsi[2]>myRsi[1] and myRsi[1]>=myRsi[3] ) and myRsi>=30 and myRsi<60// myRsi[1]=myRsi[3] exact W pattern// myRsi[1]>myRsi[3] ugly W pattern//patternText=" W "//and crossover(myRsi,30)//(myRsi<60 and myRsi>30) and myRsi>myRsi[1] and (myRsi[1]<myRsi[2] or myRsi[1]<myRsi[3]) and (myRsi[2]<30) and (myRsi[3]<30 and myRsi[4]>=30)//barcolor(shortEmaVal>longEmaVal?color.green:color.purple)//longCondition = crossover(sma(close, 14), sma(close, 28))barcolor(longCondition?color.yellow:na)strategy.entry("RSI_V_LE", strategy.long, when=longCondition )//stoploss value at 10%stopLossValue=strategy.position_avg_price - (strategy.position_avg_price*stopLoss/100) //stopLossValue=valuewhen(longCondition,low,3)//takeprofit at RSI highest reading//at RSI75 move the stopLoss to entry pricemoveStopLossUp=strategy.position_size>0 and crossunder(myRsi,70)barcolor(moveStopLossUp?color.blue:na)stopLossValue:=crossover(myRsi,70) ? strategy.position_avg_price:stopLossValue//stopLossValue:=moveStopLossUp?strategy.position_avg_price:stopLossValuersiPlotColor=longCondition ?color.yellow:color.purplersiPlotColor:= moveStopLossUp ?color.blue:rsiPlotColorplot(myRsi, title="RSI", linewidth=2, color=rsiPlotColor)//longCondition?color.yellow:#8D1699)hline(50, title="Middle Line", linestyle=hline.style_dotted)obLevel = hline(75, title="Overbought", linestyle=hline.style_dotted)osLevel = hline(25, title="Oversold", linestyle=hline.style_dotted)fill(obLevel, osLevel, title="Background", color=#9915FF, transp=90)plotshape( longCondition ? myRsi[1] : na, offset=-1, title="V Pattern", text=patternText, style=shape.labelup, location=location.absolute, color=color.purple, textcolor=color.yellow, transp=0 ) //when RSI crossing down 70 , close 1/2 position and move stop loss to average entry pricestrategy.close("RSI_V_LE", qty=strategy.position_size*1/2, when=strategy.position_size>0 and crossunder(myRsi,70))//when RSI reaches high reading 90 and crossing down close 3/4 positionstrategy.close("RSI_V_LE", qty=strategy.position_size*3/4, when=strategy.position_size>0 and crossunder(myRsi,90))//close everything when Rsi goes down below to 10 or stoploss hit //just keeping RSI cross below 10 , can work as stop loss , which also keeps you long in the trade ... however sharp declines could make large loss//so I combine RSI goes below 10 OR stoploss hit , whichever comes first - whole position closedlongCloseCondition=close<stopLossValue//crossunder(myRsi,10) or close<stopLossValuestrategy.close("RSI_V_LE", qty=strategy.position_size,when=longCloseCondition )