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
luxrun grazie Ivàn!
lee Thank you. Is it possible to convert this to a screener that displays instruments when bulli...
Iván //---------------------------------------------------------------// //PRC_Pollan Indicator /...
Faisalx ChatGPT Hola Iván. Gracias por tu excelente trabajo. Te agradecería si pudieras echarle un...
Iván ok, perfecto! me pongo con ello
Iván Hi, Sorry, but what do you mean?
luiskohnen Hola, queria saber si el indicador repinta, porque a mi me parecio que si. Saludos y gracias...
Diamant Bonsoir, L'un d'entre vous peut-il me donner les définissions de LL-HH-LH et HL. Merci d'av...
Bernard13 (Je réécris mon commentaire -français- en français car certains mots ne correspondaient pas ...
Iván 1000 indicateurs !!! brutaux
Iván Gracias! Para el screener sólo tienes que copiar el indicador y poner como condición de búsq...
Lean Muchas gracias Iván, ya lo he podido crear.
bertoluce Hello Ivan, thank you very much for the indicator. An observation: would it be possible (and...
Bateson
1 year ago
Matriciel Very nice job ! Is it possible to do the opposite because what interests me is to have the ...
YvesRobert Hi Matriciel, how can we do this, because stochastic is limited between 0 and 100 but price ...
Traderfox06 Dear zeiiermantrading, I really like your approach combining adaptive averages with MACD in...
jacquesgermain Hello IASD it's normal , when this occurs, uncheck RSI and MFI line and click then the MAC...
emiliobercial Thank you very much for sharing!
Carlose estoy de acuerdo con IASD Esta muy bien el MAD y el indicador en el precio no se ven bien...
bousalahane merci pour le partage de cet l'indicateur, j'ai rajouté un autre indicateur pour faire une s...
joaoarcher Hi, thank you for the this. Is it possible to create a screener from this indicator, so that...
KumoNoJuzza Thanks. I did not know IG had Futures. I am always missing an info or a detail. I used to th...
joaoarcher Hi, thank you for the this. Is it possible to create a screener from this indicator, so that...
superfalcio Last very good gain of the system: positions on Eurostoxx50 closed yesterday friday 06/12/2024.
Nicolas
2 years ago
3 RSI
3 RSI
2
Indicators
Violet Nicolas, you calculate iRSI, but don't use it. You show RSI in the returned values, which, a...
Nicolas Yes, that's an error. RSI instruction is set by default to 14 if you don't indicate it that'...
DELBERT Bonjour , Nicolas , je voudrais installer cet indicateur sur ma PRT , version 10.3 , mais je...
Nicolas En effet, il faut à minima une version 11. La 10.3 est tellement ancienne maintenant.. Je pe...
DELBERT Bonjour , Nicolas , merci pour ta réponse , je fais un essai et je verrais . Salutations .
Khaled Thank you Nicolas! Looks like TDI (Trader Dynamic Index). Interesting to give Exit Signal as...
Nicolas ColorBetween is an instruction added last year: https://www.prorealcode.com/documentation/co...
finplus Bonjour, serait-il possible de remplacer l'écart formé par les bandes de Bollinger par l'ATR...
robertogozzi An updated version can be found here https://www.prorealcode.com/topic/conversion-of-pine-sc...
jissey Bonjour Robertogozzi, cet indicateur est interessant mais serait-il possible de marquer la ...
robertogozzi Sure, but you should start a new topic on the Probuilder support forum. Thank you :)

Top