OPEN-SOURCE SCRIPT
RSI Smart Divergence [josseliani]

RSI Smart Divergence is an RSI divergence indicator designed to provide a clean and flexible way to work with confirmed bullish and bearish divergences.
There are many RSI divergence indicators available. I created this version because I wanted two different approaches to divergence detection in one simple tool: a selective Zone mode focused on overbought and oversold areas, and a separate Regular mode for more traditional divergence analysis.
One of the main visual features of RSI Smart Divergence is that confirmed divergences can be displayed simultaneously on the RSI and directly on the main price chart. The RSI line shows the momentum structure, while the price-chart line connects the corresponding local price extremes. This makes it possible to see the disagreement between price and RSI without manually matching oscillator pivots to candles.
ZONE MODE
Zone mode is the original logic of RSI Smart Divergence and is enabled by default.
Instead of evaluating every RSI pivot as the next divergence reference, this mode focuses specifically on divergence structures formed within the overbought and oversold zones.
For bullish divergence, the relevant RSI pivot points are evaluated within the oversold area.
For bearish divergence, the relevant RSI pivot points are evaluated within the overbought area.
Intermediate RSI pivots outside the relevant zone do not replace the previous zone reference point. This allows the indicator to compare significant momentum extremes inside the same zone even when other RSI swings occur between them.
As a result, Zone mode behaves differently from a standard adjacent-pivot divergence detector and provides a more selective view of divergence developing in already stretched momentum conditions.
REGULAR MODE
Regular mode is available as a separate optional mode.
It identifies classic regular bullish and bearish divergence using confirmed RSI pivots and corresponding local price extremes.
Additional structural filtering checks the price path between the selected endpoints and rejects structures where an intermediate price extreme invalidates the divergence being evaluated.
Regular mode is disabled by default.
The two modes operate independently and can identify different divergences. You can use Zone mode, Regular mode, or enable both at the same time.
CONFIRMED PIVOTS
Both modes use confirmed RSI pivots.
Pivot Left and Pivot Right determine how many bars are required around a potential RSI swing before it is considered confirmed.
The important setting for signal timing is Pivot Right.
For example:
Pivot Right = 3 — confirmation requires 3 bars to form to the right of the pivot.
Pivot Right = 10 — confirmation requires 10 bars to form to the right of the pivot.
Because of this confirmation process, a divergence becomes known only after the required right-side bars have formed.
The divergence lines are drawn back to the confirmed pivot locations, while the triangle marker and alert appear when the divergence is actually confirmed.
This distinction is important when reviewing historical charts: the lines identify the structure that produced the divergence, but the divergence was not known in real time until its confirmation bar.
PRICE AND RSI DISPLAY
Each confirmed divergence can be visualized in two places:
— on the RSI;
— directly on the corresponding price structure on the main chart.
The RSI line connects the confirmed momentum pivots used for the divergence.
The price-chart line connects the corresponding local price extremes.
This makes the relationship between price and oscillator structure immediately visible without manually matching RSI pivots to individual candles.
The RSI and price divergence lines can be enabled or disabled independently.
Small green and red triangles mark the confirmation of bullish and bearish divergence events in the RSI pane.
HOW I USE IT
The RSI period and pivot settings can be adjusted depending on the timeframe and the amount of market detail you want the indicator to capture.
For faster lower-timeframe trading, I may use a shorter RSI period such as 5 or 9 together with a smaller pivot setting around 3. This makes the indicator more responsive, but naturally includes more short-term market movement.
RSI 14 is a useful general starting point.
For higher timeframes, or when I want to focus on larger divergence structures, I normally keep RSI at 14 and increase the pivot setting.
For example, on a 15-minute chart I may use a pivot value around 10. This is one example configuration shown on the chart attached to this publication.
Smaller pivot settings produce faster and more frequent structures.
Larger pivot settings require more confirmation and tend to focus on broader swings.
WHAT MAKES THIS VERSION DIFFERENT
The main purpose of RSI Smart Divergence is not simply to mark every regular RSI divergence.
The original Zone mode maintains its own overbought and oversold divergence structure and ignores intermediate RSI pivots outside the relevant extreme zone when selecting the next comparison point.
Regular mode provides a separate approach for traders who also want traditional divergence detection.
Together with confirmed-pivot logic, corresponding price-extreme mapping, divergence lines on both RSI and price, adjustable structural distance and alerts, the two modes provide different ways to analyze divergence without requiring several separate indicators.
SETTINGS
RSI Length controls the RSI calculation period.
Overbought and Oversold Levels define the extreme RSI zones used by Zone mode.
Zone oversold / overbought enables the original Zone mode.
Regular enables regular divergence detection.
Pivot Left and Pivot Right control pivot confirmation.
Max bars between points limits the maximum distance between the two points of a divergence.
The RSI and price divergence lines can be shown or hidden independently.
Optional background highlighting can also be enabled for the overbought and oversold areas.
ALERTS
Alerts are available for confirmed bullish and bearish RSI divergences.
Alerts trigger when the divergence is confirmed, not retrospectively on the original pivot bar.
NOTES
RSI Smart Divergence is an analytical tool rather than an automatic trading system.
Divergence does not guarantee a market reversal. Different RSI periods and pivot settings can produce significantly different results, so settings should be selected according to the market, timeframe and trading approach being used.
The indicator should be used together with independent market analysis and appropriate risk management.
There are many RSI divergence indicators available. I created this version because I wanted two different approaches to divergence detection in one simple tool: a selective Zone mode focused on overbought and oversold areas, and a separate Regular mode for more traditional divergence analysis.
One of the main visual features of RSI Smart Divergence is that confirmed divergences can be displayed simultaneously on the RSI and directly on the main price chart. The RSI line shows the momentum structure, while the price-chart line connects the corresponding local price extremes. This makes it possible to see the disagreement between price and RSI without manually matching oscillator pivots to candles.
ZONE MODE
Zone mode is the original logic of RSI Smart Divergence and is enabled by default.
Instead of evaluating every RSI pivot as the next divergence reference, this mode focuses specifically on divergence structures formed within the overbought and oversold zones.
For bullish divergence, the relevant RSI pivot points are evaluated within the oversold area.
For bearish divergence, the relevant RSI pivot points are evaluated within the overbought area.
Intermediate RSI pivots outside the relevant zone do not replace the previous zone reference point. This allows the indicator to compare significant momentum extremes inside the same zone even when other RSI swings occur between them.
As a result, Zone mode behaves differently from a standard adjacent-pivot divergence detector and provides a more selective view of divergence developing in already stretched momentum conditions.
REGULAR MODE
Regular mode is available as a separate optional mode.
It identifies classic regular bullish and bearish divergence using confirmed RSI pivots and corresponding local price extremes.
Additional structural filtering checks the price path between the selected endpoints and rejects structures where an intermediate price extreme invalidates the divergence being evaluated.
Regular mode is disabled by default.
The two modes operate independently and can identify different divergences. You can use Zone mode, Regular mode, or enable both at the same time.
CONFIRMED PIVOTS
Both modes use confirmed RSI pivots.
Pivot Left and Pivot Right determine how many bars are required around a potential RSI swing before it is considered confirmed.
The important setting for signal timing is Pivot Right.
For example:
Pivot Right = 3 — confirmation requires 3 bars to form to the right of the pivot.
Pivot Right = 10 — confirmation requires 10 bars to form to the right of the pivot.
Because of this confirmation process, a divergence becomes known only after the required right-side bars have formed.
The divergence lines are drawn back to the confirmed pivot locations, while the triangle marker and alert appear when the divergence is actually confirmed.
This distinction is important when reviewing historical charts: the lines identify the structure that produced the divergence, but the divergence was not known in real time until its confirmation bar.
PRICE AND RSI DISPLAY
Each confirmed divergence can be visualized in two places:
— on the RSI;
— directly on the corresponding price structure on the main chart.
The RSI line connects the confirmed momentum pivots used for the divergence.
The price-chart line connects the corresponding local price extremes.
This makes the relationship between price and oscillator structure immediately visible without manually matching RSI pivots to individual candles.
The RSI and price divergence lines can be enabled or disabled independently.
Small green and red triangles mark the confirmation of bullish and bearish divergence events in the RSI pane.
HOW I USE IT
The RSI period and pivot settings can be adjusted depending on the timeframe and the amount of market detail you want the indicator to capture.
For faster lower-timeframe trading, I may use a shorter RSI period such as 5 or 9 together with a smaller pivot setting around 3. This makes the indicator more responsive, but naturally includes more short-term market movement.
RSI 14 is a useful general starting point.
For higher timeframes, or when I want to focus on larger divergence structures, I normally keep RSI at 14 and increase the pivot setting.
For example, on a 15-minute chart I may use a pivot value around 10. This is one example configuration shown on the chart attached to this publication.
Smaller pivot settings produce faster and more frequent structures.
Larger pivot settings require more confirmation and tend to focus on broader swings.
WHAT MAKES THIS VERSION DIFFERENT
The main purpose of RSI Smart Divergence is not simply to mark every regular RSI divergence.
The original Zone mode maintains its own overbought and oversold divergence structure and ignores intermediate RSI pivots outside the relevant extreme zone when selecting the next comparison point.
Regular mode provides a separate approach for traders who also want traditional divergence detection.
Together with confirmed-pivot logic, corresponding price-extreme mapping, divergence lines on both RSI and price, adjustable structural distance and alerts, the two modes provide different ways to analyze divergence without requiring several separate indicators.
SETTINGS
RSI Length controls the RSI calculation period.
Overbought and Oversold Levels define the extreme RSI zones used by Zone mode.
Zone oversold / overbought enables the original Zone mode.
Regular enables regular divergence detection.
Pivot Left and Pivot Right control pivot confirmation.
Max bars between points limits the maximum distance between the two points of a divergence.
The RSI and price divergence lines can be shown or hidden independently.
Optional background highlighting can also be enabled for the overbought and oversold areas.
ALERTS
Alerts are available for confirmed bullish and bearish RSI divergences.
Alerts trigger when the divergence is confirmed, not retrospectively on the original pivot bar.
NOTES
RSI Smart Divergence is an analytical tool rather than an automatic trading system.
Divergence does not guarantee a market reversal. Different RSI periods and pivot settings can produce significantly different results, so settings should be selected according to the market, timeframe and trading approach being used.
The indicator should be used together with independent market analysis and appropriate risk management.
オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
Indicators, updates & setups:
Free Telegram: t.me/magicdiagonals
RSI Retest Scalper: whop.com/magic-diagonals/rsi-retest-scalper-pro/
Instagram🐶: instagram.com/magicdiagonals/
Free Telegram: t.me/magicdiagonals
RSI Retest Scalper: whop.com/magic-diagonals/rsi-retest-scalper-pro/
Instagram🐶: instagram.com/magicdiagonals/
免責事項
これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。
オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
Indicators, updates & setups:
Free Telegram: t.me/magicdiagonals
RSI Retest Scalper: whop.com/magic-diagonals/rsi-retest-scalper-pro/
Instagram🐶: instagram.com/magicdiagonals/
Free Telegram: t.me/magicdiagonals
RSI Retest Scalper: whop.com/magic-diagonals/rsi-retest-scalper-pro/
Instagram🐶: instagram.com/magicdiagonals/
免責事項
これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。