RSI Divergence Detector

RSI Divergence Detector

1. Introduction

The RSI Divergence Detector is a technical indicator that automatically identifies divergences between price and the Relative Strength Index (RSI). Divergences are valuable signals in technical analysis, as they can anticipate potential trend reversals before they occur.

This indicator is especially useful for both trend-following traders and those looking to detect market turning points. Thanks to its visual implementation with color bands and dynamic alerts, it becomes an ideal tool for strategies involving RSI behavior.

2. Indicator Foundation

Divergences between price and an oscillator like RSI are early warning signs of a possible change in trend direction.

Bullish Divergence

Occurs when price prints a lower low, but the RSI shows a higher low. This suggests that despite the price drop, bearish momentum is weakening and an upward reversal could be near.

Bearish Divergence

Occurs when price makes a higher high, while the RSI shows a lower high. This indicates that although price is rising, bullish strength is fading, hinting at a possible retracement or correction.

The indicator automates the detection of these patterns on the chart, eliminating the need for manual comparison and enabling a more systematic, objective signal detection.

3. Code Logic

The code is divided into two main blocks: detection of bullish and bearish divergences, both based on comparing the average price and the RSI.

RSI and Average Price Calculation

RSI is calculated using the average price (open + high + low + close) / 4, which smooths volatility and reduces noise. The RSI period is adjustable (default: 14).

Bullish Divergence Detection

It looks for a recent lower low in price, and simultaneously a higher low in RSI. Key conditions include:

  • srcLL: current price is above its recent lowest point, and that low is lower than an older one.
  • rsiHL: current RSI is higher than its recent low, that low is above an older low, and it’s under the oversold level (30).

When both conditions are met, a green area is drawn under the RSI graph.

Bearish Divergence Detection

The inverse logic applies:

  • srcHH: current price is below its recent highest point, and that high is above an older one.
  • rsiLH: current RSI is lower than its recent high, that high is below an older high, and above the overbought level (70).

A red band is drawn above the RSI to signal potential downward reversal.

Alert System

Both divergence signals use counters to measure the number of bars since the last signal.

The ialert parameter defines the minimum how many bars a divergence remains visually highlighted. if a divergence occurred less than ialert bars ago, a colored band (green or red) is drawn on the RSI. Otherwise, the band is not displayed.

In addition, the RSI line changes color dynamically:

  • Green when there’s a bullish divergence.
  • Red when there’s a bearish divergence.
  • Blue in all other cases.

4. Indicator Settings

The indicator includes customizable parameters that allow it to be adapted to different trading styles and timeframes:

Parameter Description Default Value
rsiprd RSI calculation period 14
ob Overbought threshold 70
os Oversold threshold 30
x Short-range lookback for local highs/lows 5
z Long-range lookback for divergence validation 25
revpct Required price reversal percentage to confirm a low/high 0.01 (1%)
ialert Maximum bars to dsiplay alerts 25

Adjustment Recommendations

  • For lower timeframes (1–15 min), reduce x and z for faster signals.
  • For higher timeframes (4h, daily), increase xz, and ialert to filter stronger signals.
  • Adjust revpct for sensitivity tuning: higher values reduce noise, but may miss early entries.

5. Practical Use

The RSI Divergence Detector is versatile and works across multiple timeframes. Its effectiveness improves when used in trending contexts or around key support/resistance zones.

Recommended Timeframes

  • Intraday (5min–1h): Suitable for scalping or short-term strategies. Use lower x and z.
  • Swing trading (4h–Daily): Better for identifying significant reversals. Default or higher values work well.

Indicator Combinations

This divergence detector can be used alongside:

  • Moving averages: For trend confirmation.
  • Support/resistance levels: Divergence near these areas carries more weight.
  • Volume indicators: Validate divergence strength, especially on longer timeframes.

Limitations

While divergences are powerful, they should not be used in isolation. It is recommended to wait for price action confirmation or additional signals before trading.

6. Indicator Code

The final section contains the full ProRealTime code (ProBuilder language) for implementing the RSI Divergence Detector.

Share this

Risk disclosure:

No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.

ProRealTime ITF files and other attachments : How to import ITF files into ProRealTime platform?

PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials

avatar
Register or

Likes

avatar
Related users ' posts
ak5hay2 Works like crazy on bitcoin. Use different timeframes. Thanks a lot Doc!!!
richyowen Hi, great code thanks. Very new to this forum. Is there a way to add a 100point target on an...
lisamitch50 Morning all, Just backtested on quite a few instruments, worked well on backtesting, but tel...
Matriciel
7 years ago
Alai-n Thanks...
Bard Thanks for sharing this Verdi55. More instructions from Larry Williams website (and a fea...
Nicolas
7 years ago
Jurik RSX
v10.3
Jurik RSX
3
Indicators
hartgeld Hallo Nicolas, ein sehr guter Indikator, vielen Dank! Leider rechnet er bei mir nicht die Pe...
rigel Hi Nicolas, have you coded the Jurik alone (as Mov. average)?
Nicolas 2 versions available in this indicator: https://www.prorealcode.com/prorealtime-indicators/a...
AG1 Thanks Nicolas Still a problem in line 29 Please take a look. thanks again Alex
Nicolas code is modified in the above post, use that one.
AG1 Still a problem in line 29 Please take a look. thanks again Alex
styrke Hello Nicolas, Nice screener, I appreciate the way you always try to condense at maximum th...
Nicolas There's no particular reason. RSI is widely use with its default period and results seems re...
MaoRai54 Hi, first of all Happy New Year. Well, I've inserted your indicator in DAX 1h but I cann...
Vinks_o_7 Hi Mao Happy New Year ! This is just an improved RSI where you plot a standard price momen...
Angel Perez Ciao Francesco. First of all thanks for the indicator and also fro the screener. I do have a...
PSIDIO Ciao to you all, I also have a question and would be very happy for a helpful comment. I a...
SpreadBetMH Hi there, I have V11.1. I get the Indicator but no Arrows on the price. Kind Regards...
Alai-n Ciao Francesco, sei ancora in giro?
Metodi97 This indicator is great but can someone create strategy based on the same indicator it will ...
Nicolas
7 years ago
TradeNavigator RSI
TradeNavigator RSI
10
Indicators
Nicolas Tutte le impostazioni che hanno la parola "period" sono quelle dedicate ai periodi di cambio...
GianfrancoCeck Le chiedo una ultima cosa, ossia se è possibile personalizzare l'indicatore con una scritta ...
Nicolas Spiacente che non sia possibile, le coordinate grafiche non sono in pixel ma nel prezzo e ne...
Nicolas Your picture is too small, but for sure the problem is about the fact you are still using v1...
Rory Dryden Thanks. This looks useful.
Edelmiro Un millón... de gracias... me gustaría más, poder ofrecer euros; pero va a ser que no puedo,...
Jessar Hello, could you tell me how to use this indicator? I think the simplest things can still be...
Mirko Vaglio Interesting idea to bypass the limit of PRT about multiple timeframe, and I am just trying t...
Mirko Vaglio Looking a little bit more, now I understand what had to be absolutely obvious from the first...
Seb nice code! I'm trying to use your method to do a higher timeframe EMA, without success yet. ...
Francesco78 @snucke the results are not the same because the pictures refers to a few years ago. I am no...
snucke @Francesco78 i mean the results differ when i test on my own. so im curious of what the p...
sfl still working, using with filters like : trendFilterUp=close>average[190](close) tren...
alex Im looking for a entry when EpicMA crosses over/under trigger. Then look for exits when Epic...
rejo007 hello david, i'll try it could you tell me wich strategy do you use in real? thanks
David Somogyi Hello, I have a couple of DAX strategies of breakout and mean reversion. I'll try to post...
Roberto Blázquez Hi David, I just saw your strategy and it's good!!! I'm going to try it from today in real a...
juanj To follow new developments or get the latest version of this strategy please visit the forum...
tahar Hello Juan, I wanted to test Universal Strategy via a demo account on PRT but nothing happen...
BravoDelta @juanj wondering if you may help me please. I am looking for a simply strategy to use on the...
Wilko I am not familiar with the screener function, but I am quite certain it should be quite simp...
Gubben @Wilko have you had a look at this again since MTF support? Heard you talk on Börssnack btw..
Wilko @Gubben not really. It was something I posted to show that simpler is usually better. Hope y...

Top