Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

RSI5_50 with Divergence

A Pine Script v4 strategy built on RSI (close, 5), Pivotlow (shortTermRSI, 1) and Pivothigh (shortTermRSI, 1). It has 6 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 is 3 contracts and pays no commission. 13 settings; defaults include RSI Period 5, Long RSI Period 50 and RSI Source close.

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 RSI5_50 with Divergence repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 3 of 3 trades.
How did RSI5_50 with Divergence do on BTCUSDT 1D with default settings?
+443.31%
From 26 Jan 2024 to 21 Oct 2026, over 25 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can RSI5_50 with Divergence 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 RSI5_50 with Divergence use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does RSI5_50 with Divergence run in Zeal Terminal?
Yes
It compiles in 28 ms and runs 1,000 bars in 83 ms, in the browser.

BTCUSDT · 1D · default settings

  • RSI
  • longTermRSI
  • Middle Line
  • Overbought
  • Oversold
  • Regular Bullish
  • Hidden Bullish
  • Regular Bearish
  • Hidden Bearish
  • 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 (13)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctRSI$57,890$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. 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 92) so the engine trades the way the script says.
Net profit
+443.31%
$44,331.30
Buy and hold
+102.5%
same period
Closed trades
25
19 won · 6 lost
Profitable
76.0%
of closed trades
Profit factor
1.25
gross profit ÷ gross loss
Max drawdown
411.28%
−$293,090.00

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

    1 setting does nothing

    “RSI Source” is declared but never read.

  • 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 92, 150, 151, 152, 153, 155. The upgraded version below moves each call inside an if block.

  • Note

    Uses transp =, which v5 removed line 32

    transp = on line 32, 45, 53, 71, 79, 100, 108, 126, 134. v5 folds the transparency into the colour with color.new(c, transp).

  • Note

    Uses long =, which v5 renamed line 92

    long = on line 92. 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, pivotlow → ta.pivotlow, pivothigh → ta.pivothigh, barssince → ta.barssince, valuewhen → ta.valuewhen, crossover → ta.crossover, crossunder → ta.crossunder.
  • 6 strategy calls use the when = argument (line 92, 150, 151, 152, 153, 155). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

Same 25 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: rsi → ta.rsi
  • Line 32: transp = 65 → color.new(longTermRSI >=50 ? color.green:color.purple, 65)
  • Line 33: pivotlow → ta.pivotlow
  • Line 34: pivothigh → ta.pivothigh
24 more edits
  • Line 36: barssince → ta.barssince
  • Line 41: valuewhen → ta.valuewhen
  • Line 43: valuewhen → ta.valuewhen
  • Line 45: transp = 0 → color.new((bullCond ? bullColor : noneColor), 0)
  • Line 53: transp = 0 → color.new(bullColor, 0)
  • Line 67: valuewhen → ta.valuewhen
  • Line 69: valuewhen → ta.valuewhen
  • Line 71: transp = 0 → color.new((hiddenBullCond ? hiddenBullColor : noneColor), 0)
  • Line 79: transp = 0 → color.new(bullColor, 0)
  • Line 90: crossover → ta.crossover
  • Line 92: long = true → direction = strategy.long
  • Line 96: valuewhen → ta.valuewhen
  • Line 98: valuewhen → ta.valuewhen
  • Line 100: transp = 0 → color.new((bearCond ? bearColor : noneColor), 0)
  • Line 108: transp = 0 → color.new(bearColor, 0)
  • Line 122: valuewhen → ta.valuewhen
  • Line 124: valuewhen → ta.valuewhen
  • Line 126: transp = 0 → color.new((hiddenBearCond ? hiddenBearColor : noneColor), 0)
  • Line 134: transp = 0 → color.new(bearColor, 0)
  • Line 150: crossover → ta.crossover
  • Line 151: crossover → ta.crossover
  • Line 152: crossover → ta.crossover
  • Line 153: crossover → ta.crossover
  • Line 155: crossunder → ta.crossunder
⋯// © mohanee-//@version=4+//@version=5//GOOGL setting  5 ,50 close, 3 , 1  profitLevel at 75 and No stop Loss shows win rate 99.03 % profit factor 5830.152⋯stopLoss = input(title="Stop Loss%(if checked 8% rule applied)", defval=false)-shortTermRSI = rsi(close,len)+shortTermRSI = ta.rsi(close,len)-longTermRSI = rsi(close,longRSILen)+longTermRSI = ta.rsi(close,longRSILen)rangeUpper = input(title="Max of Lookback Range", defval=60)⋯osLevel = hline(30, title="Oversold", linestyle=hline.style_dotted)-fill(obLevel, osLevel, title="Background", color=longTermRSI >=50 ? color.green:color.purple, transp=65)  // longTermRSI >=50+fill(obLevel, osLevel, title="Background", color=color.new(longTermRSI >=50 ? color.green:color.purple, 65))  // longTermRSI >=50-plFound = na(pivotlow(shortTermRSI, lbL, lbR)) ? false : true+plFound = na(ta.pivotlow(shortTermRSI, lbL, lbR)) ? false : true-phFound = na(pivothigh(shortTermRSI, lbL, lbR)) ? false : true+phFound = na(ta.pivothigh(shortTermRSI, lbL, lbR)) ? false : true_inRange(cond) =>-    bars = barssince(cond == true)+    bars = ta.barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper⋯// shortTermRSI: Higher Low-oscHL = shortTermRSI[lbR] > valuewhen(plFound, shortTermRSI[lbR], 1) and _inRange(plFound[1])+oscHL = shortTermRSI[lbR] > ta.valuewhen(plFound, shortTermRSI[lbR], 1) and _inRange(plFound[1])// Price: Lower Low-priceLL = low[lbR] < valuewhen(plFound, low[lbR], 1)+priceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1)bullCond = plotBull and priceLL and oscHL and plFound⋯     linewidth=2,-     color=(bullCond ? bullColor : noneColor),-     transp=0+     color=color.new((bullCond ? bullColor : noneColor), 0)     )⋯     location=location.absolute,-     color=bullColor,+     color=color.new(bullColor, 0),-     textcolor=textColor,-     transp=0+     textcolor=textColor     )⋯// shortTermRSI: Lower Low-oscLL = shortTermRSI[lbR] < valuewhen(plFound, shortTermRSI[lbR], 1) and _inRange(plFound[1])+oscLL = shortTermRSI[lbR] < ta.valuewhen(plFound, shortTermRSI[lbR], 1) and _inRange(plFound[1])// Price: Higher Low-priceHL = low[lbR] > valuewhen(plFound, low[lbR], 1)+priceHL = low[lbR] > ta.valuewhen(plFound, low[lbR], 1)hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound⋯     linewidth=2,-     color=(hiddenBullCond ? hiddenBullColor : noneColor),-     transp=0+     color=color.new((hiddenBullCond ? hiddenBullColor : noneColor), 0)     )⋯     location=location.absolute,-     color=bullColor,+     color=color.new(bullColor, 0),-     textcolor=textColor,-     transp=0+     textcolor=textColor     )-longCondition= longTermRSI >=50  and ( (bullCond or hiddenBullCond ) )  or  (strategy.position_size>0 and crossover(shortTermRSI,20) )+longCondition= longTermRSI >=50  and ( (bullCond or hiddenBullCond ) )  or  (strategy.position_size>0 and ta.crossover(shortTermRSI,20) )//last condition above is to leg in if you are already in the Long trade, -strategy.entry(id="RSIDivLE", long=true,  when=longCondition)+strategy.entry(id="RSIDivLE", direction = strategy.long,  when=longCondition)//------------------------------------------------------------------------------⋯// shortTermRSI: Lower High-oscLH = shortTermRSI[lbR] < valuewhen(phFound, shortTermRSI[lbR], 1) and _inRange(phFound[1])+oscLH = shortTermRSI[lbR] < ta.valuewhen(phFound, shortTermRSI[lbR], 1) and _inRange(phFound[1])// Price: Higher High-priceHH = high[lbR] > valuewhen(phFound, high[lbR], 1)+priceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1)bearCond = plotBear and priceHH and oscLH and phFound⋯     linewidth=2,-     color=(bearCond ? bearColor : noneColor),-     transp=0+     color=color.new((bearCond ? bearColor : noneColor), 0)     )⋯     location=location.absolute,-     color=bearColor,+     color=color.new(bearColor, 0),-     textcolor=textColor,-     transp=0+     textcolor=textColor     )⋯// shortTermRSI: Higher High-oscHH = shortTermRSI[lbR] > valuewhen(phFound, shortTermRSI[lbR], 1) and _inRange(phFound[1])+oscHH = shortTermRSI[lbR] > ta.valuewhen(phFound, shortTermRSI[lbR], 1) and _inRange(phFound[1])// Price: Lower High-priceLH = high[lbR] < valuewhen(phFound, high[lbR], 1)+priceLH = high[lbR] < ta.valuewhen(phFound, high[lbR], 1)hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound⋯     linewidth=2,-     color=(hiddenBearCond ? hiddenBearColor : noneColor),-     transp=0+     color=color.new((hiddenBearCond ? hiddenBearColor : noneColor), 0)     )⋯     location=location.absolute,-     color=bearColor,+     color=color.new(bearColor, 0),-     textcolor=textColor,-     transp=0+     textcolor=textColor     )⋯//partial profit-strategy.close(id="RSIDivLE", comment="TP1", qty=strategy.position_size*3/4, when=strategy.position_size>0 and (longTermRSI>=takeProfitRSILevel or crossover(longTermRSI,90)))+strategy.close(id="RSIDivLE", comment="TP1", qty=strategy.position_size*3/4, when=strategy.position_size>0 and (longTermRSI>=takeProfitRSILevel or ta.crossover(longTermRSI,90)))-strategy.close(id="RSIDivLE",comment="TP2",   qty=strategy.position_size*3/4 , when=crossover(longTermRSI,70))+strategy.close(id="RSIDivLE",comment="TP2",   qty=strategy.position_size*3/4 , when=ta.crossover(longTermRSI,70))-strategy.close(id="RSIDivLE",comment="TP3",   qty=strategy.position_size/2, when=crossover(longTermRSI,65))+strategy.close(id="RSIDivLE",comment="TP3",   qty=strategy.position_size/2, when=ta.crossover(longTermRSI,65))-strategy.close(id="RSIDivLE",comment="TP4",   qty=strategy.position_size/2 , when=crossover(longTermRSI,60))+strategy.close(id="RSIDivLE",comment="TP4",   qty=strategy.position_size/2 , when=ta.crossover(longTermRSI,60))//close the whole position when stoploss hits or longTermRSI goes below 30-strategy.close(id="RSIDivLE",comment="Exit",    when=crossunder(longTermRSI,30) or close<stopLossVal)+strategy.close(id="RSIDivLE",comment="Exit",    when=ta.crossunder(longTermRSI,30) or close<stopLossVal)

Clean v5

VerifiedDownload the v5 script

Same 25 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 6: input() → input.int()
  • Line 7: input() → input.int()
  • Line 8: input() → input.source()
  • Line 9: input() → input.int()
  • Line 10: input() → input.int()
  • Line 11: input() → input.int()
13 more edits
  • Line 12: input() → input.bool()
  • Line 15: input() → input.int()
  • Line 16: input() → input.int()
  • Line 17: input() → input.bool()
  • Line 18: input() → input.bool()
  • Line 19: input() → input.bool()
  • Line 20: input() → input.bool()
  • Line 88: when = longCondition → if block
  • Line 142: when = strategy.position_size>0 and (longTermRSI>=takeProfitRSILevel or ta.crossover(longTermRSI,90)) → if block
  • Line 143: when = ta.crossover(longTermRSI,70) → if block
  • Line 144: when = ta.crossover(longTermRSI,65) → if block
  • Line 145: when = ta.crossover(longTermRSI,60) → if block
  • Line 147: when = ta.crossunder(longTermRSI,30) or close<stopLossVal → if block
⋯strategy(title="RSI5_50 with Divergence", overlay=false,pyramiding=2, default_qty_type=strategy.fixed, default_qty_value=3,    initial_capital=10000, currency=currency.USD)-len = input(title="RSI Period", minval=1, defval=5)+len = input.int(title="RSI Period", minval=1, defval=5)-longRSILen = input(title="Long RSI Period", minval=10, defval=50)+longRSILen = input.int(title="Long RSI Period", minval=10, defval=50)-src = input(title="RSI Source", defval=close)+src = input.source(title="RSI Source", defval=close)-lbR = input(title="Pivot Lookback Right", defval=3)+lbR = input.int(title="Pivot Lookback Right", defval=3)-lbL = input(title="Pivot Lookback Left", defval=1)+lbL = input.int(title="Pivot Lookback Left", defval=1)-takeProfitRSILevel = input(title="Take Profit at RSI Level", minval=50, defval=75)+takeProfitRSILevel = input.int(title="Take Profit at RSI Level", minval=50, defval=75)-stopLoss = input(title="Stop Loss%(if checked 8% rule applied)", defval=false)+stopLoss = input.bool(title="Stop Loss%(if checked 8% rule applied)", defval=false)shortTermRSI = ta.rsi(close,len)longTermRSI = ta.rsi(close,longRSILen)-rangeUpper = input(title="Max of Lookback Range", defval=60)+rangeUpper = input.int(title="Max of Lookback Range", defval=60)-rangeLower = input(title="Min of Lookback Range", defval=5)+rangeLower = input.int(title="Min of Lookback Range", defval=5)-plotBull = input(title="Plot Bullish", defval=true)+plotBull = input.bool(title="Plot Bullish", defval=true)-plotHiddenBull = input(title="Plot Hidden Bullish", defval=true)+plotHiddenBull = input.bool(title="Plot Hidden Bullish", defval=true)-plotBear = input(title="Plot Bearish", defval=true)+plotBear = input.bool(title="Plot Bearish", defval=true)-plotHiddenBear = input(title="Plot Hidden Bearish", defval=false)+plotHiddenBear = input.bool(title="Plot Hidden Bearish", defval=false)bearColor = color.purple⋯//last condition above is to leg in if you are already in the Long trade, -strategy.entry(id="RSIDivLE", direction = strategy.long,  when=longCondition)+if longCondition+    strategy.entry(id="RSIDivLE", direction = strategy.long)//------------------------------------------------------------------------------⋯//partial profit-strategy.close(id="RSIDivLE", comment="TP1", qty=strategy.position_size*3/4, when=strategy.position_size>0 and (longTermRSI>=takeProfitRSILevel or ta.crossover(longTermRSI,90)))+if strategy.position_size>0 and (longTermRSI>=takeProfitRSILevel or ta.crossover(longTermRSI,90))+    strategy.close(id="RSIDivLE", comment="TP1", qty=strategy.position_size*3/4)-strategy.close(id="RSIDivLE",comment="TP2",   qty=strategy.position_size*3/4 , when=ta.crossover(longTermRSI,70))+if ta.crossover(longTermRSI,70)+    strategy.close(id="RSIDivLE",comment="TP2",   qty=strategy.position_size*3/4 )-strategy.close(id="RSIDivLE",comment="TP3",   qty=strategy.position_size/2, when=ta.crossover(longTermRSI,65))+if ta.crossover(longTermRSI,65)+    strategy.close(id="RSIDivLE",comment="TP3",   qty=strategy.position_size/2)-strategy.close(id="RSIDivLE",comment="TP4",   qty=strategy.position_size/2 , when=ta.crossover(longTermRSI,60))+if ta.crossover(longTermRSI,60)+    strategy.close(id="RSIDivLE",comment="TP4",   qty=strategy.position_size/2 )//close the whole position when stoploss hits or longTermRSI goes below 30-strategy.close(id="RSIDivLE",comment="Exit",    when=ta.crossunder(longTermRSI,30) or close<stopLossVal)+if ta.crossunder(longTermRSI,30) or close<stopLossVal+    strategy.close(id="RSIDivLE",comment="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: 25 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=6//GOOGL setting  5 ,50 close, 3 , 1  profitLevel at 75 and No stop Loss shows win rate 99.03 % profit factor 5830.152⋯

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 1shortTermRSI
Long RSI Period50int · min 10longTermRSI
RSI Sourceclosesourceunused
Pivot Lookback Right3intplFound phFound oscHL priceLL oscLL priceHL oscLH priceHH oscHH priceLH Regular Bullish Regular Bullish Label Hidden Bullish Hidden Bullish Label Regular Bearish Regular Bearish Label Hidden Bearish Hidden Bearish Label
Pivot Lookback Left1intplFound phFound
Take Profit at RSI Level75int · min 50close RSIDivLE
Stop Loss%(if checked 8% rule applied)falseboolstopLossVal
Max of Lookback Range60intline 37
Min of Lookback Range5intline 37
Plot BullishtrueboolbullCond
Plot Hidden BullishtrueboolhiddenBullCond
Plot BearishtrueboolbearCond
Plot Hidden BearishfalseboolhiddenBearCond

What it calculates

  • RSI (rsi, ta.rsi in v5)close, RSI Period (5)shortTermRSI · line 13
  • RSI (rsi, ta.rsi in v5)close, Long RSI Period (50)longTermRSI · line 14
  • Pivotlow (pivotlow, ta.pivotlow in v5)shortTermRSI, Pivot Lookback Left (1), Pivot Lookback Right (3)plFound · line 33
  • Pivothigh (pivothigh, ta.pivothigh in v5)shortTermRSI, Pivot Lookback Left (1), Pivot Lookback Right (3)phFound · line 34

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 · 5longRSILenLong RSI Periodsetting · 50lbRPivot Lookback Rightsetting · 3lbLPivot Lookback Leftsetting · 1lowlowprice datahighhighprice datatakeProfitRSILevelTake Profit at RSI Levelsetting · 75shortTermRSIRSI→ shortTermRSIlongTermRSIRSI→ longTermRSIplFoundPivotlow→ plFoundphFoundPivothigh→ phFoundstopLossValstopLossValvaluelongConditionlongConditionconditionbarsbarsconditionoscHL, oscLLoscHL · oscLL2 conditionspriceLL, priceHLpriceLL · priceHL2 conditionsbullCondbullCondconditionhiddenBullCondhiddenBullCondconditionoscLH, oscHHoscLH · oscHH2 conditionspriceHH, priceLHpriceHH · priceLH2 conditionsbearCondbearCondconditionhiddenBearCondhiddenBearCondconditionbearColor, bullColor, hiddenBullColor, hiddenBearColor, textColor, noneColorColourbearColor · bullColor +4entry:RSIDivLEOpen RSIDivLEstrategy.entryclose:RSIDivLEClose RSIDivLEstrategy.closeplot:27RSIplotplot:28longTermRSIplothline:29Middle Linehlinehline:30Overboughthlinehline:31Oversoldhlinefill:BackgroundBackgroundfillplot:45Regular Bullishplotplotshape:53Regular Bullish Labelplotshapeplot:71Hidden Bullishplotplotshape:79Hidden Bullish Labelplotshapeplot:100Regular Bearishplotplotshape:108Regular Bearish Labelplotshapeplot:126Hidden Bearishplotplotshape:134Hidden Bearish Labelplotshape

Order rules

OrderFires whenBy defaultLine
Open RSIDivLE longlongConditionlongTermRSI >=50 and ( (bullCond or hiddenBullCond ) ) or (strategy.position_size>0 and crossover(shortTermRSI,20) )On92
Close RSIDivLEstrategy.position_size>0 and (longTermRSI>=takeProfitRSILevel or crossover(longTermRSI,90))On150
Close RSIDivLEcrossover(longTermRSI,70)On151
Close RSIDivLEcrossover(longTermRSI,65)On152
Close RSIDivLEcrossover(longTermRSI,60)On153
Close RSIDivLEcrossunder(longTermRSI,30) or close<stopLossValOn155

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.

3/3trades 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 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+443.3%+102.5%2576%1.25411.3%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+727.4%+5.5%2990%38.74138.1%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−71.5%+9.8%2548%0.20106.9%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+29.9%+8.4%9100%—14.3%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+1.7%+16.7%1861%1.455.2%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.6%+21.5%2879%1.431.8%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+4.9%+148.3%3187%1.4314.9%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+4.9%+17.1%2673%3.375.4%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

Settings heatmap

Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (RSI Period 5, Long RSI Period 60) made +1,812.0% before 26 Dec 2025 and 0.0% after it, worse than the defaults' +224.6% after. Tuning on the past did not carry forward. 92% of the 48 combinations made money in-sample and 63% out-of-sample.

Before 26 Dec 2025 · in-sample
Long RSI Period ↓ · RSI Period →345679
25+345%+362%+1,340%+950%+1,159%+994%
30−566%−768%+210%+538%+945%+1,018%
35+53%−428%+549%+902%+957%+1,030%
43+742%−57%+32%+223%+1,114%+1,187%
50+458%+130%+219%+340%+1,223%+1,296%
60+1,628%+1,555%+1,812%+1,656%+1,617%+1,690%
70+866%+866%+965%+965%+819%+819%
85+604%+626%+595%+595%+595%+595%
From 26 Dec 2025 · out-of-sample
Long RSI Period ↓ · RSI Period →345679
25+91%+125%+211%+596%+596%+652%
30+258%+291%+377%+693%+693%+693%
35+301%+309%+309%+459%+459%+459%
43+33%+36%+36%+41%+50%+50%
50+215%+225%+225%+226%+229%+261%
600%0%0%0%0%0%
700%0%0%0%0%0%
850%0%0%0%0%0%

Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market2190%$138,990.00
Sideways market40%−$94,658.60
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?

56.5%

The 95th percentile of the worst drawdown when the same 25 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 41.8% to 56.5%; the tick is what actually happened, 65.1%. Order luck alone moves it this much.

0%75%
All 25 trades
SideEntryExitBarsP&L
long23 Mar 2024 63,796.6026 Mar 2024 69,880.003$9,125.04
long23 Mar 2024 63,796.609 Nov 2024 76,509.80231$19,069.70
long6 Apr 2024 67,820.609 Nov 2024 76,509.80217$6,516.86
long6 Apr 2024 67,820.6012 Nov 2024 88,648.00220$23,430.80
long6 Apr 2024 67,820.6028 Nov 2024 95,863.10236$15,773.90
long6 Apr 2024 67,820.602 Dec 2024 97,185.20240$16,517.60
long30 Nov 2024 97,460.002 Dec 2024 97,185.202−$334.95
long30 Nov 2024 97,460.005 Dec 2024 98,587.305$1,004.02
long30 Nov 2024 97,460.007 Dec 2024 99,740.807$1,015.69
long30 Nov 2024 97,460.0016 Dec 2024 104,464.0016$1,559.48
long30 Nov 2024 97,460.0022 May 2025 109,644.00173$2,712.84
long3 Jan 2025 96,984.8022 May 2025 109,644.00139$17,579.50
long3 Jan 2025 96,984.8012 Jul 2025 117,528.00190$33,101.30
long7 Jun 2025 104,288.0012 Jul 2025 117,528.0035$9,192.47
long7 Jun 2025 104,288.0023 Jul 2025 119,954.0046$18,060.30
long7 Jun 2025 104,288.0014 Aug 2025 123,306.0068$21,924.60
long24 Jul 2025 118,756.0014 Aug 2025 123,306.0021$4,202.71
long24 Jul 2025 118,756.0022 Aug 2026 78,338.00394−$83,924.50
long25 Sep 2025 113,307.0022 Aug 2026 78,338.00331−$16,148.40
long25 Sep 2025 113,307.004 Sep 2026 81,270.40344−$40,657.80
long25 Sep 2025 113,307.007 Sep 2026 80,341.80347−$20,918.10
long25 Sep 2025 113,307.0022 Sep 2026 86,620.00362−$16,934.30
long14 Sep 2026 76,842.0022 Sep 2026 86,620.008$11,564.70
long14 Sep 2026 76,842.002 Oct 2026 84,880.1018$7,303.67
long14 Sep 2026 76,842.004 Oct 2026 84,753.6020$3,594.37

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
RSI5_50 with Divergence this page—v4 strategy+443.3%25411.3%
RSI Centered Pivots by OztheWozrsi pivotlow pivothighv4 strategy+98.0%4160.2%
RSI Divergence X Ichimoku Cloud X 200EMA by tradethrillsrsi pivotlow pivothighv4 strategy−196,793.0%71,854.6%
Pivot Point Breakout by EduardoMattjepivotlow pivothighv5 strategy+93.0%2532.3%
Monthly Returns of a Strategy in a Chart by QuantNomadpivothigh pivotlowv5 strategy+21.0%7613.0%
ZigZag by Zeal Terminalpivothigh pivotlowv5 indicatorindicator

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 28 msWith a workaround 1,000 bars in 83 msNot measured
PineTSNo 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 92) 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//GOOGL setting  5 ,50 close, 3 , 1  profitLevel at 75 and No stop Loss shows win rate 99.03 % profit factor 5830.152strategy(title="RSI5_50 with Divergence", overlay=false,pyramiding=2, default_qty_type=strategy.fixed, default_qty_value=3,    initial_capital=10000, currency=currency.USD)len = input(title="RSI Period", minval=1, defval=5)longRSILen = input(title="Long RSI Period", minval=10, defval=50)src = input(title="RSI Source", defval=close)lbR = input(title="Pivot Lookback Right", defval=3)lbL = input(title="Pivot Lookback Left", defval=1)takeProfitRSILevel = input(title="Take Profit at RSI Level", minval=50, defval=75)stopLoss = input(title="Stop Loss%(if checked 8% rule applied)", defval=false)shortTermRSI = rsi(close,len)longTermRSI = rsi(close,longRSILen)rangeUpper = input(title="Max of Lookback Range", defval=60)rangeLower = input(title="Min of Lookback Range", defval=5)plotBull = input(title="Plot Bullish", defval=true)plotHiddenBull = input(title="Plot Hidden Bullish", defval=true)plotBear = input(title="Plot Bearish", defval=true)plotHiddenBear = input(title="Plot Hidden Bearish", defval=false)bearColor = color.purplebullColor = color.greenhiddenBullColor = color.new(color.green, 80)hiddenBearColor = color.new(color.red, 80)textColor = color.whitenoneColor = color.new(color.white, 100)plot(shortTermRSI, title="RSI", linewidth=2, color=#8D1699)plot(longTermRSI, title="longTermRSI", linewidth=2, color=color.orange)hline(50, title="Middle Line", linestyle=hline.style_dotted)obLevel = hline(70, title="Overbought", linestyle=hline.style_dotted)osLevel = hline(30, title="Oversold", linestyle=hline.style_dotted)fill(obLevel, osLevel, title="Background", color=longTermRSI >=50 ? color.green:color.purple, transp=65)  // longTermRSI >=50plFound = na(pivotlow(shortTermRSI, lbL, lbR)) ? false : truephFound = na(pivothigh(shortTermRSI, lbL, lbR)) ? false : true_inRange(cond) =>    bars = barssince(cond == true)    rangeLower <= bars and bars <= rangeUpper//------------------------------------------------------------------------------// Regular Bullish// shortTermRSI: Higher LowoscHL = shortTermRSI[lbR] > valuewhen(plFound, shortTermRSI[lbR], 1) and _inRange(plFound[1])// Price: Lower LowpriceLL = low[lbR] < valuewhen(plFound, low[lbR], 1)bullCond = plotBull and priceLL and oscHL and plFoundplot(     plFound ? shortTermRSI[lbR] : na,     offset=-lbR,     title="Regular Bullish",     linewidth=2,     color=(bullCond ? bullColor : noneColor),     transp=0     )plotshape(     bullCond ? shortTermRSI[lbR] : na,     offset=-lbR,     title="Regular Bullish Label",     text=" Bull ",     style=shape.labelup,     location=location.absolute,     color=bullColor,     textcolor=textColor,     transp=0     )//------------------------------------------------------------------------------// Hidden Bullish// shortTermRSI: Lower LowoscLL = shortTermRSI[lbR] < valuewhen(plFound, shortTermRSI[lbR], 1) and _inRange(plFound[1])// Price: Higher LowpriceHL = low[lbR] > valuewhen(plFound, low[lbR], 1)hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFoundplot(     plFound ? shortTermRSI[lbR] : na,     offset=-lbR,     title="Hidden Bullish",     linewidth=2,     color=(hiddenBullCond ? hiddenBullColor : noneColor),     transp=0     )plotshape(     hiddenBullCond ? shortTermRSI[lbR] : na,     offset=-lbR,     title="Hidden Bullish Label",     text=" H Bull ",     style=shape.labelup,     location=location.absolute,     color=bullColor,     textcolor=textColor,     transp=0     )longCondition= longTermRSI >=50  and ( (bullCond or hiddenBullCond ) )  or  (strategy.position_size>0 and crossover(shortTermRSI,20) )//last condition above is to leg in if you are already in the Long trade, strategy.entry(id="RSIDivLE", long=true,  when=longCondition)//------------------------------------------------------------------------------// Regular Bearish// shortTermRSI: Lower HighoscLH = shortTermRSI[lbR] < valuewhen(phFound, shortTermRSI[lbR], 1) and _inRange(phFound[1])// Price: Higher HighpriceHH = high[lbR] > valuewhen(phFound, high[lbR], 1)bearCond = plotBear and priceHH and oscLH and phFoundplot(     phFound ? shortTermRSI[lbR] : na,     offset=-lbR,     title="Regular Bearish",     linewidth=2,     color=(bearCond ? bearColor : noneColor),     transp=0     )plotshape(     bearCond ? shortTermRSI[lbR] : na,     offset=-lbR,     title="Regular Bearish Label",     text=" Bear ",     style=shape.labeldown,     location=location.absolute,     color=bearColor,     textcolor=textColor,     transp=0     )//------------------------------------------------------------------------------// Hidden Bearish// shortTermRSI: Higher HighoscHH = shortTermRSI[lbR] > valuewhen(phFound, shortTermRSI[lbR], 1) and _inRange(phFound[1])// Price: Lower HighpriceLH = high[lbR] < valuewhen(phFound, high[lbR], 1)hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFoundplot(     phFound ? shortTermRSI[lbR] : na,     offset=-lbR,     title="Hidden Bearish",     linewidth=2,     color=(hiddenBearCond ? hiddenBearColor : noneColor),     transp=0     )plotshape(     hiddenBearCond ? shortTermRSI[lbR] : na,     offset=-lbR,     title="Hidden Bearish Label",     text=" H Bear ",     style=shape.labeldown,     location=location.absolute,     color=bearColor,     textcolor=textColor,     transp=0     )          //calculate stop LossstopLossVal = stopLoss==true ? ( strategy.position_avg_price -  (strategy.position_avg_price*0.08) ) : 0//partial profitstrategy.close(id="RSIDivLE", comment="TP1", qty=strategy.position_size*3/4, when=strategy.position_size>0 and (longTermRSI>=takeProfitRSILevel or crossover(longTermRSI,90)))strategy.close(id="RSIDivLE",comment="TP2",   qty=strategy.position_size*3/4 , when=crossover(longTermRSI,70))strategy.close(id="RSIDivLE",comment="TP3",   qty=strategy.position_size/2, when=crossover(longTermRSI,65))strategy.close(id="RSIDivLE",comment="TP4",   qty=strategy.position_size/2 , when=crossover(longTermRSI,60))//close the whole position when stoploss hits or longTermRSI goes below 30strategy.close(id="RSIDivLE",comment="Exit",    when=crossunder(longTermRSI,30) or close<stopLossVal)