OPEN-SOURCE SCRIPT
Cập nhật RSI Divergence (Nikko)

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.
🧠 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.
Phát hành các Ghi chú
Added full customization of all the colors and the heatmap transparency. Enjoy customizing the indicator to your liking.Phát hành các Ghi chú
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.
Phát hành các Ghi chú
Fixed the visualization by enlarging the window, enabling a broader and more accurate display of the chart.Phát hành các Ghi chú
Re-ajusted the visual again for a better overbought and oversold visualization.Only cosmetic change.
Phát hành các Ghi chú
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
Phát hành các Ghi chú
Update fixing these bugs- Fixed regression calculation bug where b2 incorrectly used a instead of a2.
- Added safe offset variables (offsetBull, offsetBear) to prevent invalid ta.barssince() indexing.
- Corrected array indexing safety for bullish and bearish regression loops.
- Fixed minor typos and unused expressions (xxo, etc.).
- Ensured no division-by-zero occurs in regression formulas.
- Cleaned redundant conditions while keeping logic 100% identical.
- Ensured heatmap and plot variables remain valid under all inputs.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Twitter X: x.com/cryptonikkoid
Web: nikkoid.com
I do not answer to private messages. Use the comment section of the idea or script, or use Telegram.
Web: nikkoid.com
I do not answer to private messages. Use the comment section of the idea or script, or use Telegram.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Twitter X: x.com/cryptonikkoid
Web: nikkoid.com
I do not answer to private messages. Use the comment section of the idea or script, or use Telegram.
Web: nikkoid.com
I do not answer to private messages. Use the comment section of the idea or script, or use Telegram.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.