Pine Script Relative Vigor Index (RVI)

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

Last Updated on: Expertise: Intermediate

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 Pine Script, 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.

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 Pine Script'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).

Positive RVI values indicate a stronger closing price relative to the opening, suggesting bullish vigor. Negative values suggest bearish vigor.

Basic Relative Vigor Index (RVI) Implementation in Pine Script

Pine Script v5 provides a convenient built-in function `ta.rvi()` for calculating the Relative Vigor Index and its signal line.

//@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)
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.

Practical RVI Trading Strategies

1. RVI and Signal Line Crossover (Primary Signal)

Crossovers between the RVI line and its signal line are the most common way to generate trading signals, indicating a shift in short-term momentum or a potential trend change.

//@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)

2. RVI Zero Line Crossover

The zero line in RVI acts as a clear divider between bullish and bearish vigor. Crossovers can confirm the direction of the underlying momentum.

//@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)

3. RVI Divergence Strategy

Divergence between price and RVI can signal a potential trend reversal, indicating that the vigor of the move is weakening even if price continues its existing trend.

//@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.")

Optimizing RVI Performance

To get the most from the Relative Vigor Index in Pine Script:

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.

Common RVI Pitfalls

Conclusion

The Relative Vigor Index (RVI) is an insightful momentum oscillator in Pine Script 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.