OPEN-SOURCE SCRIPT
RVI Divergence Detector with Custom SMA Filter (v6)

This script enhances the classic Relative Vigor Index (RVI) by integrating divergence detection with a user-configurable SMA filter applied directly to the RVI oscillator. The goal is to help traders identify high-probability reversal and continuation signals by combining momentum analysis with dynamic baseline filtering.
How it works:
- The RVI measures the conviction behind price moves by comparing closing vs. opening prices relative to the high-low range over a 10-period window.
- Divergences are detected when price makes a new high/low but the RVI does not:
- Regular Bullish: Price makes a lower low, RVI makes a higher low → potential reversal up.
- Hidden Bullish: Price makes a higher low, RVI makes a lower low → trend continuation.
- Inverse logic applies for bearish cases.
- A customizable SMA (default: 14 periods) is plotted on the RVI line. This acts as a dynamic reference to assess whether divergences occur in strong momentum zones (far from SMA) or neutral zones (near SMA), helping filter out weaker signals.
- Users can adjust:
- Pivot lookback range (min/max bars)
- SMA period (1–200)
- Visibility of bullish/bearish and hidden/regular divergences
Why this version adds value:
Unlike basic RVI scripts, this adaptation introduces a configurable trend filter (SMA) and clear visual labeling ("D" for regular, "H" for hidden) with colored lines (green/red) connecting oscillator and price pivots—making divergences instantly recognizable. The logic is optimized for both scalping (short SMA) and swing trading (longer SMA).
Credits:
Based on the original RVI divergence concept by madoqa. This is an open-source adaptation under the Mozilla Public License 2.0. No financial advice. Use at your own risk.
How it works:
- The RVI measures the conviction behind price moves by comparing closing vs. opening prices relative to the high-low range over a 10-period window.
- Divergences are detected when price makes a new high/low but the RVI does not:
- Regular Bullish: Price makes a lower low, RVI makes a higher low → potential reversal up.
- Hidden Bullish: Price makes a higher low, RVI makes a lower low → trend continuation.
- Inverse logic applies for bearish cases.
- A customizable SMA (default: 14 periods) is plotted on the RVI line. This acts as a dynamic reference to assess whether divergences occur in strong momentum zones (far from SMA) or neutral zones (near SMA), helping filter out weaker signals.
- Users can adjust:
- Pivot lookback range (min/max bars)
- SMA period (1–200)
- Visibility of bullish/bearish and hidden/regular divergences
Why this version adds value:
Unlike basic RVI scripts, this adaptation introduces a configurable trend filter (SMA) and clear visual labeling ("D" for regular, "H" for hidden) with colored lines (green/red) connecting oscillator and price pivots—making divergences instantly recognizable. The logic is optimized for both scalping (short SMA) and swing trading (longer SMA).
Credits:
Based on the original RVI divergence concept by madoqa. This is an open-source adaptation under the Mozilla Public License 2.0. No financial advice. Use at your own risk.
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。