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.
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.
The calculation of the RVI involves smoothed numerators and denominators over a specified period:
//@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)
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.
//@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)
//@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)
//@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.")
To get the most from the Relative Vigor Index in Pinescript:
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.
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.
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