Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (3)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctRSI$10,150$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.
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

Verified

Same 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  ⋯

Clean v5

VerifiedDownload the v5 script

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.

SettingDefaultType and rangeFeeds
RSI Period5int · min 1myRsi
Buy at RSI 30int · min 5 · max 60longCondition
Stop Loss %8int · min 1stopLossValue

What it calculates

  • RSI (rsi, ta.rsi in v5)close, RSI Period (5)myRsi · line 13
  • EMA (ema, ta.ema in v5)close, 50longEmaVal · line 14
  • EMA (ema, ta.ema in v5)close, 20shortEmaVal · line 15
  • EMA (ema, ta.ema in v5)close, 20isEma20AboveEma50 · line 19
  • Crossover (crossover, ta.crossover in 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.

closecloseprice datalenRSI Periodsetting · 5stopLossStop Loss %setting · 8lowlowprice databuyRsiEntryBuy at RSI setting · 30myRsiRSI→ myRsilongEmaValEMA→ longEmaValshortEmaValEMA→ shortEmaValisEma20AboveEma50EMA→ isEma20AboveEma50stopLossValueCrossover→ stopLossValuelongConditionlongConditionconditionlongCloseConditionlongCloseConditionconditionmoveStopLossUpmoveStopLossUpconditionrsiPlotColorColourrsiPlotColorentry:RSI_V_LEOpen RSI_V_LEstrategy.entryclose:RSI_V_LEClose RSI_V_LEstrategy.closebarcolor:33barcolorbarcolorbarcolor:41barcolorbarcolorplot:46RSIplothline:48Middle Linehlinehline:49Overboughthlinehline:50Oversoldhlinefill:BackgroundBackgroundfillplotshape:52V Patternplotshape

Order rules

OrderFires whenBy defaultLine
Open RSI_V_LE longlongConditionema(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)On34
Close RSI_V_LEstrategy.position_size>0 and crossunder(myRsi,70)On66
Close RSI_V_LEstrategy.position_size>0 and crossunder(myRsi,90)On68
Close RSI_V_LElongCloseConditionclose<stopLossValueOn74

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.

1/1trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+1.2%+102.5%3171%1.213.3%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+0.5%+5.5%2576%1.630.5%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+3.4%+9.8%1856%1.564.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+1.5%+8.4%4293%22.030.3%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.3%+16.7%1553%1.062.6%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+1.8%+21.5%4794%8.361.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.1%+148.3%3284%0.994.3%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+2.1%+17.1%4384%2.421.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 barsTradesWonP&L
Rising market1963%−$141.21
Sideways market1283%$266.00
Falling market0—$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.

0%5%
All 31 trades
SideEntryExitBarsP&L
long20 Mar 2024 67,840.509 Apr 2024 69,146.0020$9.62
long20 Mar 2024 67,840.501 May 2024 58,365.0042−$69.84
long14 Apr 2024 65,661.801 May 2024 58,365.0017−$111.06
long18 Apr 2024 63,470.101 May 2024 58,365.0013−$79.98
long4 Oct 2024 62,086.0021 Oct 2024 67,377.5017$82.82
long4 Oct 2024 62,086.0031 Oct 2024 70,292.0027$0.42
long11 Oct 2024 62,540.0031 Oct 2024 70,292.0020$60.26
long11 Oct 2024 62,540.0014 Nov 2024 87,325.6034$145.47
long11 Oct 2024 62,540.0025 Nov 2024 93,010.0045$29.80
long11 Oct 2024 62,540.009 Dec 2024 97,276.5059$16.99
long11 Oct 2024 62,540.0018 Dec 2024 100,204.0068$9.21
long11 Oct 2024 62,540.007 Jan 2025 96,954.6088$8.42
long24 Dec 2024 98,663.607 Jan 2025 96,954.6014−$17.50
long31 Dec 2024 93,576.007 Jan 2025 96,954.607$0.43
long31 Dec 2024 93,576.0019 Jan 2025 101,332.0019$82.30
long10 Jan 2025 94,726.1019 Jan 2025 101,332.009$0.16
long10 Jan 2025 94,726.1022 Jan 2025 103,707.0012$47.76
long10 Jan 2025 94,726.1025 Feb 2025 88,680.4046−$32.15
long3 Feb 2025 101,329.0025 Feb 2025 88,680.4022−$127.95
long6 Jun 2025 104,288.0011 Jun 2025 108,645.005$21.00
long6 Jun 2025 104,288.0030 Jun 2025 107,147.0024$13.78
long23 Jun 2025 105,334.0030 Jun 2025 107,147.007$4.30
long23 Jun 2025 105,334.0015 Jul 2025 117,758.0022$44.70
long23 Jun 2025 105,334.0015 Jul 2025 117,758.0022$44.70
long3 Aug 2025 114,209.0011 Aug 2025 118,686.008$19.96
long3 Aug 2025 114,209.0014 Aug 2025 118,295.0011$9.11
long3 Aug 2025 114,209.0010 Sep 2025 113,960.0038−$0.55
long22 Aug 2025 116,936.0010 Sep 2025 113,960.0019−$26.01
long24 Sep 2025 113,307.007 Oct 2025 121,333.0013$36.08
long24 Sep 2025 113,307.007 Oct 2025 121,333.0013$36.08
long23 May 2026 76,752.002 Jun 2026 66,760.8010−$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.

ScriptSharesTypeNetTradesMax drawdown
RSI V Pattern strategy this page—v4 strategy+1.2%313.3%
RSI Cross [xaurr] by livetrendrsi emav4 strategy+24.4%5335.3%
Bitpanda Coinrule Template by joshuajcoop01rsi emav5 strategy−2.8%44.6%
RSI with Slow and Fast MA Crossing Strategy (by Coinrule) by Coinrulersi emav5 strategy−2.8%44.6%
RSI of VWAP by mohaneersi emav4 strategyNo trades on this market
EMA SCALPEUR + RSi - SHORT by YukalMoonrsi emav5 strategyNo trades on this market

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 18 msYes 1,000 bars in 47 msNot measured
PineTSNo 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 )