RSI Divergence (Pine v4)
Feb 6, 2020

The RSI Divergence indicator is a technical analysis tool designed to identify and highlight potential trend reversals and continuations by detecting regular and hidden divergences between price action and the Relative Strength Index (RSI).
Usage
The RSI Divergence indicator is used to spot discrepancies between price movement and momentum. By comparing recent price peaks and valleys with corresponding RSI levels, traders can identify potential exhaustion in a current trend or the buildup of momentum for a new one.
- Regular Bullish Divergence: Occurs when price makes a lower low while the RSI makes a higher low. This suggests a potential upward reversal.
- Regular Bearish Divergence: Occurs when price makes a higher high while the RSI makes a lower high. This suggests a potential downward reversal.
- Hidden Bullish Divergence: Occurs when price makes a higher low while the RSI makes a lower low. This often signals a continuation of an existing uptrend.
- Hidden Bearish Divergence: Occurs when price makes a lower high while the RSI makes a higher high. This often signals a continuation of an existing downtrend.
Details
The script operates by identifying pivot points within the RSI values. A pivot high is confirmed when a peak is surrounded by at least two lower values on the right, and a pivot low is confirmed when a trough is surrounded by at least two higher values on the right.
The framework compares these pivot points to previous ones within a lookback window (defaulting to a range between 5 and 60 bars). If the relationship between price extremes and RSI extremes satisfies the divergence criteria, the indicator plots the corresponding signal. The implementation includes an optional Moving Average (MA) applied to the RSI to help traders visualize the smoothed trend of momentum alongside the raw oscillator.
Settings
Oscillator
- Source: The price data used to calculate the RSI (e.g., Close, Open, HL2).
- Length: The number of bars used in the RSI calculation.
Moving Average
- Type: The smoothing method used for the RSI signal line (SMA, EMA, SMMA, WMA, or VWMA).
- Length: The period for the chosen moving average type.
Divergence Plots
- Bullish: Toggles the visibility of regular bullish divergence signals.
- Bearish: Toggles the visibility of regular bearish divergence signals.
- Hidden Bull: Toggles the visibility of hidden bullish divergence signals.
- Hidden Bear: Toggles the visibility of hidden bearish divergence signals.
FAQ
How can I access RSI Divergence? You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.
What is the difference between regular and hidden divergence? Regular divergences generally signal a potential trend reversal, while hidden divergences typically suggest that the current trend is likely to continue.
Can I set alerts for specific divergence types? Yes, the script includes built-in alert conditions for all four types of divergences (Regular Bullish, Regular Bearish, Hidden Bullish, and Hidden Bearish) which can be configured via the TradingView alerts menu.
Free indicator
Get free access to this indicator on the platforms below.
Unlock the entire LuxAlgo Library
Every indicator, every strategy, full charts, and complete access to Quant — our AI agent.