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提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。