OPEN-SOURCE SCRIPT
RSI Divergence Detector

RSI Divergence Detector with automatic pivot based detection
Spots bullish and bearish RSI divergences automatically by connecting pivot highs and lows on the RSI panel.
🔍 What it does
This indicator detects when price and RSI momentum disagree. One of the most reliable early warning signals in technical analysis.
Regular Bullish Divergence: Price makes a lower low while RSI makes a higher low. Momentum is improving despite price weakness, potential reversal to the upside.
Regular Bearish Divergence: Price makes a higher high while RSI makes a lower high. Momentum is fading despite price strength, potential reversal to the downside.
Hidden Bullish Divergence (need to turn on in options): Price makes a higher low while RSI makes a lower low. Trend continuation signal the pullback is likely over.
Hidden Bearish Divergence (need to turn on in options): Price makes a lower high while RSI makes a higher high. Downtrend continuation signal, the bounce is likely over.
📊 Visual Design
- Clean RSI line that changes color: green in oversold (below 30), red in overbought (above 70), white in the middle
- Subtle gradient fills on overbought/oversold zones
- Solid lines connecting divergence pivots on the RSI panel (green for bullish, red for bearish)
- Dashed lines for hidden divergences (when enabled)
- Small triangle markers when divergence is detected
⚙️ Settings
RSI Length: Default 14. Standard setting that works across most timeframes.
Pivot Lookback: Default 5. How many bars are needed to confirm a pivot point. Lower (3) = more signals. Higher (8-10) = fewer but stronger divergences.
Max Divergence Width: Default 60. Maximum bars allowed between two pivots forming a divergence. On daily charts, 60 bars is roughly 3 months.
Recommended settings by timeframe:
- Daily: Pivot 5, Width 60 (default)
- 4H: Pivot 5, Width 100
- Weekly: Pivot 3, Width 30
- 1H: Pivot 5, Width 120
Hidden divergence is OFF by default. Learn to read regular divergences first, then enable hidden for trend continuation signals.
🔔 Alerts
Built-in alert conditions for: Bullish Divergence, Bearish Divergence, Hidden Bullish, Hidden Bearish, Any Regular, and Any Divergence.
⚠️ Important Notes
Divergence signals appear with a delay equal to the Pivot Lookback setting (default 5 bars) because the indicator needs bars after a potential pivot to confirm it was a real turning point. This is by design accuracy over speed.
Divergence is a warning signal, not an entry trigger. Use it alongside other technical analysis, price action, and your own risk management. Not every divergence leads to a reversal.
This indicator is for educational and informational purposes only. Not financial advice.
Spots bullish and bearish RSI divergences automatically by connecting pivot highs and lows on the RSI panel.
🔍 What it does
This indicator detects when price and RSI momentum disagree. One of the most reliable early warning signals in technical analysis.
Regular Bullish Divergence: Price makes a lower low while RSI makes a higher low. Momentum is improving despite price weakness, potential reversal to the upside.
Regular Bearish Divergence: Price makes a higher high while RSI makes a lower high. Momentum is fading despite price strength, potential reversal to the downside.
Hidden Bullish Divergence (need to turn on in options): Price makes a higher low while RSI makes a lower low. Trend continuation signal the pullback is likely over.
Hidden Bearish Divergence (need to turn on in options): Price makes a lower high while RSI makes a higher high. Downtrend continuation signal, the bounce is likely over.
📊 Visual Design
- Clean RSI line that changes color: green in oversold (below 30), red in overbought (above 70), white in the middle
- Subtle gradient fills on overbought/oversold zones
- Solid lines connecting divergence pivots on the RSI panel (green for bullish, red for bearish)
- Dashed lines for hidden divergences (when enabled)
- Small triangle markers when divergence is detected
⚙️ Settings
RSI Length: Default 14. Standard setting that works across most timeframes.
Pivot Lookback: Default 5. How many bars are needed to confirm a pivot point. Lower (3) = more signals. Higher (8-10) = fewer but stronger divergences.
Max Divergence Width: Default 60. Maximum bars allowed between two pivots forming a divergence. On daily charts, 60 bars is roughly 3 months.
Recommended settings by timeframe:
- Daily: Pivot 5, Width 60 (default)
- 4H: Pivot 5, Width 100
- Weekly: Pivot 3, Width 30
- 1H: Pivot 5, Width 120
Hidden divergence is OFF by default. Learn to read regular divergences first, then enable hidden for trend continuation signals.
🔔 Alerts
Built-in alert conditions for: Bullish Divergence, Bearish Divergence, Hidden Bullish, Hidden Bearish, Any Regular, and Any Divergence.
⚠️ Important Notes
Divergence signals appear with a delay equal to the Pivot Lookback setting (default 5 bars) because the indicator needs bars after a potential pivot to confirm it was a real turning point. This is by design accuracy over speed.
Divergence is a warning signal, not an entry trigger. Use it alongside other technical analysis, price action, and your own risk management. Not every divergence leads to a reversal.
This indicator is for educational and informational purposes only. Not financial advice.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.