OPEN-SOURCE SCRIPT
Updated

RSI Divergence (Nikko)

6 267
RSI Divergence by Nikko

🧠 RSI Divergence Detector — Nikko Edition This script is an enhanced RSI Divergence detector built with Pine Script v6, modified for better visuals and practical usability. It uses linear regression to detect bullish and bearish divergences between the RSI and price action — one of the most reliable early signals in technical analysis.

✅ Improvements from the Original:

- Clean divergence lines using regression fitting.
- Optional label display to reduce clutter (Display Labels toggle).
- Adjustable line thickness (Display Line Width).
- A subtle heatmap background to highlight RSI overbought/oversold zones.
- Uses max accuracy with high calc_bars_count and custom extrapolation window.

🔍 How It Works: The script applies linear regression (least squares method) on both RSI data, and Price (close) data.

It then compares the direction of RSI vs. direction of Price over a set length. If price is making higher highs while RSI makes lower highs, it's a bearish divergence. If price is making lower lows while RSI makes higher lows, it's a bullish divergence. Additional filters (e.g., momentum and slope thresholds) are used to validate only strong divergences.

🔧 Input Parameters: RSI Length: The RSI period (default: 14). RSI Divergence Length: The lookback period for regression (default: 25). Source: Which price data to calculate RSI from (default: close). Display Labels: Show/hide “Bullish” or “Bearish” labels on the chart. Display Line Width: Adjusts how thick the plotted divergence lines appear.

📣 Alerts: Alerts are built-in for both RSI Buy (bullish divergence) and RSI Sell (bearish divergence) so you can use it in automation or notifications.

🚀 Personal Note: I’ve been using this script daily in my own trading, which is why I took time to improve both the logic and visual clarity. If you want a divergence tool that doesn't clutter your chart but gives strong signals, this might be what you're looking for.
Release Notes
Added full customization of all the colors and the heatmap transparency. Enjoy customizing the indicator to your liking.
Release Notes
RSI Divergence Script Update (by Nikko)

✅ Upgrades:
Option to hide the heatmap and show a flat background instead.
Added a smoothed SMA to improve RSI trend readability.
Introduced a red/green gradient for RSI when overbought/oversold.
Added option to disable the SMA plot if not needed.
Line width can now be set for SMA, divergence lines, and RSI plot.

🛠 Fixes:
Corrected the top hline from 80 to 70, aligning overbought/oversold at 70/30, not 80/30.
Release Notes
Fixed the visualization by enlarging the window, enabling a broader and more accurate display of the chart.
Release Notes
Re-ajusted the visual again for a better overbought and oversold visualization.
Only cosmetic change.
Release Notes
Finally, I’ve updated this script to make it even more functional!
Since it’s an all-in-one RSI indicator, I’ve added the Stochastic RSI on top of it, making it even more powerful for identifying precise momentum shifts.
The Stochastic RSI (StochRSI) measures the RSI’s position relative to its recent high-low range, helping to spot overbought and oversold conditions earlier than the traditional RSI.
You can easily disable the StochRSI in the settings if you prefer to use the original RSI-only version — it will behave exactly as before.

I have also changed to upper and lower bounds for the oversold and overbought area from 30-70 to 20-80

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.