Logo
OFFLINEPIXEL
/ pinescript-strategies / pine-script-rvi

$ Pinescript Relative Vigor Index (RVI)

Master this unique momentum oscillator in TradingView's Pinescript that measures the vigor of a price move by comparing its closing price to its trading range.

500+ Clients Helped
100% Satisfaction
Live Trading Ready
⚠️
Trading financial markets carries risk. All content (PineScript code, indicators, strategies) on this website is for educational purposes only. Past performance is not indicative of future results. By using any code or information from this site, you agree that you are solely responsible for your trading decisions. The author disclaims all liability for any losses incurred. To gain from experts experiences, You can always try our Invite Only Scripts
01

What is the Relative Vigor Index (RVI)?

The Relative Vigor Index (RVI), developed by John Ehlers, is a momentum oscillator that measures the "vigor" or strength of a price move by comparing the closing price to the trading range of the bar. The underlying assumption is that in an uptrend, prices tend to close near the high of the daily range, while in a downtrend, they tend to close near the low. RVI oscillates around a zero line and typically includes a signal line, which is a smoothed version of the RVI itself.

In Pinescript, RVI is a valuable tool for traders seeking to confirm trend direction, identify potential reversals through crossovers, and spot divergence patterns, by assessing the conviction behind each price bar's movement.

02

Components and Calculation

The calculation of the RVI involves smoothed numerators and denominators over a specified period:

  1. Numerator: `Close - Open` (measures the strength of the move within the bar)
  2. Denominator: `High - Low` (measures the total range of the bar)
  3. Smoothed Numerator (SN): A Simple Moving Average (SMA) of `(Close - Open)` over `length` periods (e.g., 10 periods). Often, a 4-period symmetrical weighted moving average is applied to a sum of (Close - Open) over 4 bars, but for simplicity, we'll refer to the common SMA approach or Pinescript's built-in.
  4. Smoothed Denominator (SD): An SMA of `(High - Low)` over `length` periods. Similar smoothing logic as SN.
  5. RVI Line: `SN / SD`
  6. RVI Signal Line: A Simple Moving Average of the RVI Line over a shorter `signal_length` period (e.g., 4 periods).
03

Basic Relative Vigor Index (RVI) Implementation in Pinescript

pine-script@terminal
//@version=5
indicator("My Relative Vigor Index", overlay=false) // overlay=false to plot in a separate pane

// Inputs for RVI lengths
length = input.int(10, title="RVI Length", minval=1)
signalLength = input.int(4, title="Signal Line Length", minval=1)

// Calculate RVI and its signal line using the built-in function
// ta.rvi takes the length for RVI and the length for the signal line
[rviValue, signalValue] = ta.rvi(length, signalLength)

// Plot the RVI line
plot(rviValue, title="RVI", color=color.blue, linewidth=2)

// Plot the Signal Line
plot(signalValue, title="Signal", color=color.orange, linewidth=2)

// Plot the Zero Line
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted)
$ ✓ Compiled successfully
04

Conviction from Close

Conviction from Close

RVI focuses on where the price closes within its bar's range. A close near the high indicates buying conviction, near the low indicates selling conviction.

05

Practical RVI Trading Strategies

06

1. RVI and Signal Line Crossover (Primary Signal)

pine-script@terminal
//@version=5
strategy("RVI Crossover Strategy", overlay=true)

// Inputs for RVI lengths
length = input.int(10, title="RVI Length", minval=1)
signalLength = input.int(4, title="Signal Line Length", minval=1)

// Calculate RVI and its signal line
[rviValue, signalValue] = ta.rvi(length, signalLength)

// Plot RVI and Signal in a separate pane for visualization
plot(rviValue, "RVI", color.blue, display=display.pane_only)
plot(signalValue, "Signal", color.orange, display=display.pane_only)
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted, display=display.pane_only)

// Define conditions for entries
longSignal = ta.crossover(rviValue, signalValue)
shortSignal = ta.crossunder(rviValue, signalValue)

// Strategy entries/exits
if (longSignal)
    strategy.entry("Long", strategy.long)

if (shortSignal)
    strategy.entry("Short", strategy.short)
$ ✓ Compiled successfully
07

2. RVI Zero Line Crossover

pine-script@terminal
//@version=5
strategy("RVI Zero Line Crossover Strategy", overlay=true)

// Inputs for RVI length
length = input.int(10, title="RVI Length", minval=1)
signalLength = input.int(4, title="Signal Line Length", minval=1) // Signal not strictly needed for this strategy

// Calculate RVI
[rviValue, signalValue] = ta.rvi(length, signalLength) // Signal value still calculated by ta.rvi

// Plot RVI in a separate pane
plot(rviValue, "RVI", color.blue, display=display.pane_only)
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted, display=display.pane_only)

// Define conditions for entries
longSignal = ta.crossover(rviValue, 0)
shortSignal = ta.crossunder(rviValue, 0)

// Strategy entries/exits
if (longSignal)
    strategy.entry("Long", strategy.long)

if (shortSignal)
    strategy.entry("Short", strategy.short)
$ ✓ Compiled successfully
08

3. RVI Divergence Strategy

pine-script@terminal
//@version=5
indicator("RVI Divergence Scanner", overlay=true)

// Inputs for RVI lengths
length = input.int(10, title="RVI Length", minval=1)
signalLength = input.int(4, title="Signal Line Length", minval=1)

// Calculate RVI and its signal line
[rviValue, signalValue] = ta.rvi(length, signalLength)

// Plot RVI and Signal in a separate pane
plot(rviValue, "RVI", color.blue)
plot(signalValue, "Signal", color.orange)
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted)

// Simple divergence detection (conceptual, robust detection requires advanced pivot logic)
// This is a simplified example focusing on price vs RVI divergence.

// Bullish Divergence (Price lower low, RVI higher low)
bullishDivergence = close[2] > close[1] and close[1] > close and rviValue[2] < rviValue[1] and rviValue[1] < rviValue

// Bearish Divergence (Price higher high, RVI lower high)
bearishDivergence = close[2] < close[1] and close[1] < close and rviValue[2] > rviValue[1] and rviValue[1] > rviValue

plotshape(bullishDivergence, title="Bullish Divergence", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(bearishDivergence, title="Bearish Divergence", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)

alertcondition(bullishDivergence, "Bullish RVI Divergence", "Potential bullish reversal based on RVI divergence.")
alertcondition(bearishDivergence, "Bearish RVI Divergence", "Potential bearish reversal based on RVI divergence.")
$ ✓ Compiled successfully
09

Optimizing RVI Performance

To get the most from the Relative Vigor Index in Pinescript:

  • Parameter Tuning: The standard `length` of 10 for RVI and 4 for the signal line are generally good starting points. Shorter lengths will make the indicator more reactive but also more prone to false signals (whipsaws). Longer lengths will smooth it out but introduce more lag. Experiment to find optimal settings for your specific asset and timeframe.
  • Combine with Trend Filters: RVI, like many oscillators, can generate false signals in sideways markets. It's best used in conjunction with a trend-following indicator (e.g., a longer-period EMA or ADX) to confirm the underlying trend direction. Then use RVI to time entries/exits within that trend.
  • Confirm with Price Action: Always look for RVI signals to be confirmed by price action, such as bullish/bearish candlestick patterns, breaks of support/resistance, or chart patterns.
  • Divergence is Powerful: Pay special attention to divergence signals, as these often indicate a significant shift in underlying momentum or conviction, making them more reliable reversal signals.
  • Consider Volume: While RVI inherently uses high-low range which can be related to volatility, it doesn't directly incorporate volume. Combining it with a volume indicator (like MFI or On-Balance Volume) can provide additional confirmation.
10

Relative to Range

Relative to Range

RVI's strength lies in its comparison of closing price to the bar's entire range, which offers a different perspective on momentum than just comparing close to open or close to previous close.

11

Common RVI Pitfalls

  • Whipsaws in Sideways Markets: In choppy or range-bound markets, RVI can generate frequent crossovers and zero-line crosses, leading to numerous false signals.
  • Lag: Despite being a momentum indicator, RVI still has some inherent lag due to its smoothing components. It will not perfectly pinpoint exact tops or bottoms.
  • Subjectivity: Interpreting the significance of crossovers or divergence can sometimes be subjective without clear rules or additional confirmation.
  • Not a Standalone Indicator: RVI should always be used as part of a broader trading system, complementing other indicators and price action analysis for better risk management.
  • False Divergence: Like all divergence signals, RVI divergence can sometimes appear early, and the trend might continue for some time after the divergence emerges.
12

Conclusion

Conclusion

The Relative Vigor Index (RVI) is an insightful momentum oscillator in Pinescript for TradingView. By comparing the closing price to the trading range, it provides a unique measure of the "vigor" or conviction behind price movements. Whether used for identifying shifts in momentum through RVI/signal line crossovers, confirming trend direction via zero-line crosses, or spotting powerful reversals through divergence, the RVI offers valuable insights into market dynamics. By understanding its calculation, thoughtfully tuning its parameters, and integrating it strategically with other technical analysis tools, you can leverage the RVI to enhance your trading decisions and gain a clearer perspective on buying and selling pressure.

Enhance Your Trading

Get a high-performance Pinescript analysis tool for actionable market insights, designed for traders on the move.

This strategy runs in live mode on TradingView, helping you identify potential opportunities.

Get Pinescript Strategy