RSI Divergence
Jun 27, 2025

The RSI Divergence indicator is a technical analysis tool that utilizes linear regression to identify potential bullish and bearish divergences between price action and the Relative Strength Index (RSI). By comparing the slope of price movements against the slope of RSI momentum, the script aims to provide early signals for trend exhaustion or potential reversals with improved visual clarity and filtering.
Usage
The indicator can be used to spot trend reversals by looking for discrepancies between price and the RSI oscillator. A Bullish Divergence occurs when price makes a lower low while the RSI makes a higher low (indicated by green labels and regression lines). Conversely, a Bearish Divergence occurs when price makes a higher high while the RSI makes a lower high (indicated by red labels and regression lines).
The script uses linear regression (least squares method) rather than simple peak-to-peak connections to determine the trend of both data sets. This provides a more statistical approach to divergence detection. Users can also toggle a Stochastic RSI overlay and an SMA of the RSI to further refine their entries or exits.
Details
The script performs the following core operations:
- Linear Regression Fitting: It calculates the best-fit line for both RSI and Price over a specific lookback period.
- Slope Comparison: It validates a divergence by checking if the slopes of the price regression and RSI regression are moving in opposite directions.
- Momentum Filtering: It applies thresholds to ensure that only significant divergences—those with sufficient price and RSI movement—are signaled.
- Visual Enhancements: Includes a dynamic heatmap background based on RSI levels and regression lines plotted on both the oscillator pane and the price chart (using
force_overlay).
Settings
Settings
- Display Stochastic RSI: Toggles the visibility of the Stochastic RSI components (K and D lines).
- K / D / Stochastic Length: Parameters for the calculation of the Stochastic RSI.
- RSI Length / Source: Determines the period and price source used for the standard RSI calculation.
- SMA Length / Enable SMA: Controls the lookback period and visibility of the Moving Average applied to the RSI.
- RSI Divergence length: The lookback window (number of bars) used for the linear regression calculation.
- Display Labels: Show or hide the "Bullish" and "Bearish" text labels on the chart.
- Hide Heatmap: Toggles the dynamic background coloring between overbought and oversold zones.
- Line Widths: Separate settings to adjust the thickness of Divergence lines, RSI lines, and SMA lines.
🎨 Visual Settings
- Heatmap Transparency: Adjusts the opacity of the background heatmap.
- Color Settings: Comprehensive color pickers for the RSI, SMA, overbought/oversold zones, labels, and divergence lines.
FAQ
How do I interpret the regression lines?
The lines represent the "best fit" trend of price and RSI over the selected divergence length. When these lines point in opposite directions, it indicates a loss of momentum relative to price movement, signaling a potential reversal.
What are the built-in alerts?
The script includes alert conditions for Bullish Divergence, Bearish Divergence, as well as RSI Overbought (>70) and Oversold (<30) crossovers.
How can I access this tool?
You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.
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.