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
- 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
VerifiedSame 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)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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| RSI Period | 5 | int · min 1 | shortTermRSI |
| Long RSI Period | 50 | int · min 10 | longTermRSI |
| RSI Source | close | source | unused |
| Pivot Lookback Right | 3 | int | plFound 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 Left | 1 | int | plFound phFound |
| Take Profit at RSI Level | 75 | int · min 50 | close RSIDivLE |
| Stop Loss%(if checked 8% rule applied) | false | bool | stopLossVal |
| Max of Lookback Range | 60 | int | line 37 |
| Min of Lookback Range | 5 | int | line 37 |
| Plot Bullish | true | bool | bullCond |
| Plot Hidden Bullish | true | bool | hiddenBullCond |
| Plot Bearish | true | bool | bearCond |
| Plot Hidden Bearish | false | bool | hiddenBearCond |
What it calculates
- RSI (
rsi,ta.rsiin v5)close, RSI Period (5)shortTermRSI · line 13 - RSI (
rsi,ta.rsiin v5)close, Long RSI Period (50)longTermRSI · line 14 - Pivotlow (
pivotlow,ta.pivotlowin v5)shortTermRSI, Pivot Lookback Left (1), Pivot Lookback Right (3)plFound · line 33 - Pivothigh (
pivothigh,ta.pivothighin 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open RSIDivLE long | longConditionlongTermRSI >=50 and ( (bullCond or hiddenBullCond ) ) or (strategy.position_size>0 and crossover(shortTermRSI,20) ) | On | 92 |
| Close RSIDivLE | strategy.position_size>0 and (longTermRSI>=takeProfitRSILevel or crossover(longTermRSI,90)) | On | 150 |
| Close RSIDivLE | crossover(longTermRSI,70) | On | 151 |
| Close RSIDivLE | crossover(longTermRSI,65) | On | 152 |
| Close RSIDivLE | crossover(longTermRSI,60) | On | 153 |
| Close RSIDivLE | crossunder(longTermRSI,30) or close<stopLossVal | On | 155 |
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 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 | +443.3% | +102.5% | 25 | 76% | 1.25 | 411.3% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +727.4% | +5.5% | 29 | 90% | 38.74 | 138.1% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −71.5% | +9.8% | 25 | 48% | 0.20 | 106.9% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +29.9% | +8.4% | 9 | 100% | — | 14.3% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +1.7% | +16.7% | 18 | 61% | 1.45 | 5.2% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.6% | +21.5% | 28 | 79% | 1.43 | 1.8% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +4.9% | +148.3% | 31 | 87% | 1.43 | 14.9% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +4.9% | +17.1% | 26 | 73% | 3.37 | 5.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.
| Long RSI Period ↓ · RSI Period → | 3 | 4 | 5 | 6 | 7 | 9 |
|---|---|---|---|---|---|---|
| 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% |
| Long RSI Period ↓ · RSI Period → | 3 | 4 | 5 | 6 | 7 | 9 |
|---|---|---|---|---|---|---|
| 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% |
| 60 | 0% | 0% | 0% | 0% | 0% | 0% |
| 70 | 0% | 0% | 0% | 0% | 0% | 0% |
| 85 | 0% | 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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 21 | 90% | $138,990.00 |
| Sideways market | 4 | 0% | −$94,658.60 |
| 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?
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.
All 25 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 23 Mar 2024 63,796.60 | 26 Mar 2024 69,880.00 | 3 | $9,125.04 |
| long | 23 Mar 2024 63,796.60 | 9 Nov 2024 76,509.80 | 231 | $19,069.70 |
| long | 6 Apr 2024 67,820.60 | 9 Nov 2024 76,509.80 | 217 | $6,516.86 |
| long | 6 Apr 2024 67,820.60 | 12 Nov 2024 88,648.00 | 220 | $23,430.80 |
| long | 6 Apr 2024 67,820.60 | 28 Nov 2024 95,863.10 | 236 | $15,773.90 |
| long | 6 Apr 2024 67,820.60 | 2 Dec 2024 97,185.20 | 240 | $16,517.60 |
| long | 30 Nov 2024 97,460.00 | 2 Dec 2024 97,185.20 | 2 | −$334.95 |
| long | 30 Nov 2024 97,460.00 | 5 Dec 2024 98,587.30 | 5 | $1,004.02 |
| long | 30 Nov 2024 97,460.00 | 7 Dec 2024 99,740.80 | 7 | $1,015.69 |
| long | 30 Nov 2024 97,460.00 | 16 Dec 2024 104,464.00 | 16 | $1,559.48 |
| long | 30 Nov 2024 97,460.00 | 22 May 2025 109,644.00 | 173 | $2,712.84 |
| long | 3 Jan 2025 96,984.80 | 22 May 2025 109,644.00 | 139 | $17,579.50 |
| long | 3 Jan 2025 96,984.80 | 12 Jul 2025 117,528.00 | 190 | $33,101.30 |
| long | 7 Jun 2025 104,288.00 | 12 Jul 2025 117,528.00 | 35 | $9,192.47 |
| long | 7 Jun 2025 104,288.00 | 23 Jul 2025 119,954.00 | 46 | $18,060.30 |
| long | 7 Jun 2025 104,288.00 | 14 Aug 2025 123,306.00 | 68 | $21,924.60 |
| long | 24 Jul 2025 118,756.00 | 14 Aug 2025 123,306.00 | 21 | $4,202.71 |
| long | 24 Jul 2025 118,756.00 | 22 Aug 2026 78,338.00 | 394 | −$83,924.50 |
| long | 25 Sep 2025 113,307.00 | 22 Aug 2026 78,338.00 | 331 | −$16,148.40 |
| long | 25 Sep 2025 113,307.00 | 4 Sep 2026 81,270.40 | 344 | −$40,657.80 |
| long | 25 Sep 2025 113,307.00 | 7 Sep 2026 80,341.80 | 347 | −$20,918.10 |
| long | 25 Sep 2025 113,307.00 | 22 Sep 2026 86,620.00 | 362 | −$16,934.30 |
| long | 14 Sep 2026 76,842.00 | 22 Sep 2026 86,620.00 | 8 | $11,564.70 |
| long | 14 Sep 2026 76,842.00 | 2 Oct 2026 84,880.10 | 18 | $7,303.67 |
| long | 14 Sep 2026 76,842.00 | 4 Oct 2026 84,753.60 | 20 | $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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| RSI5_50 with Divergence this page | — | v4 strategy | +443.3% | 25 | 411.3% |
| RSI Centered Pivots by OztheWoz | rsi pivotlow pivothigh | v4 strategy | +98.0% | 4 | 160.2% |
| RSI Divergence X Ichimoku Cloud X 200EMA by tradethrills | rsi pivotlow pivothigh | v4 strategy | −196,793.0% | 7 | 1,854.6% |
| Pivot Point Breakout by EduardoMattje | pivotlow pivothigh | v5 strategy | +93.0% | 25 | 32.3% |
| Monthly Returns of a Strategy in a Chart by QuantNomad | pivothigh pivotlow | v5 strategy | +21.0% | 76 | 13.0% |
| ZigZag by Zeal Terminal | pivothigh pivotlow | v5 indicator | indicator | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 28 ms | With a workaround 1,000 bars in 83 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as long = true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 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)