Master this enhanced momentum oscillator in TradingView's Pinescript that incorporates volume into its calculation, providing more reliable overbought/oversold levels and stronger divergence signals.
Volume-Adjusted RSI (VARSI) is an adaptation of the popular Relative Strength Index (RSI) that aims to improve its reliability by incorporating volume. While the traditional RSI only considers the magnitude of price changes, VARSI weights these price changes by their associated trading volume. The core idea is that price movements backed by higher volume are more significant and should have a greater impact on the momentum calculation than price movements on lower volume.
By integrating volume, VARSI seeks to filter out "weak" momentum signals that occur on low trading activity and to emphasize "strong" momentum signals that are supported by substantial market participation. This can lead to:
The calculation of Volume-Adjusted RSI builds upon the traditional RSI formula by introducing a volume weighting step. Here's a breakdown:
//@version=5
indicator("My Volume-Adjusted RSI (VARSI)", overlay=false) // overlay=false to plot in a separate pane
// Input for VARSI length (smoothing period, similar to standard RSI)
length = input.int(14, title="VARSI Length", minval=1)
// Calculate price changes
up_change = math.max(close - close[1], 0)
down_change = math.max(close[1] - close, 0)
// Calculate volume-adjusted price changes
volume_adj_up = up_change * volume
volume_adj_down = down_change * volume
// Calculate average volume-adjusted gains and losses using RMA (Wilder's smoothing)
avg_gain_vol_adj = ta.rma(volume_adj_up, length)
avg_loss_vol_adj = ta.rma(volume_adj_down, length)
// Calculate Volume-Adjusted Relative Strength (VARS)
// Handle division by zero for avg_loss_vol_adj
vars = if avg_loss_vol_adj != 0
avg_gain_vol_adj / avg_loss_vol_adj
else
if avg_gain_vol_adj > 0
1000000000.0
else
1.0
// Calculate Volume-Adjusted RSI (VARSI)
v_rsi = 100 - (100 / (1 + vars))
// Plot the VARSI line
plot(v_rsi, title="Volume-Adjusted RSI", color=color.blue, linewidth=2)
// Plot standard RSI levels
hline(70, "Overbought", color.red, linestyle=hline.style_dashed)
hline(30, "Oversold", color.green, linestyle=hline.style_dashed)
hline(50, "Mid-Line", color.gray, linestyle=hline.style_dotted)
// Highlight overbought/oversold zones for clarity
bgcolor(v_rsi > 70 ? color.new(color.red, 90) : na, title="Overbought Zone")
bgcolor(v_rsi < 30 ? color.new(color.green, 90) : na, title="Oversold Zone")
VARSI's key advantage is that it gives more weight to price movements that are supported by higher volume, potentially making its signals for overbought/oversold conditions and divergences more reliable.
//@version=5
strategy("VARSI Overbought/Oversold Strategy", overlay=true)
length = input.int(14, title="VARSI Length", minval=1)
obLevel = input.int(70, title="Overbought Level", minval=50, maxval=90)
osLevel = input.int(30, title="Oversold Level", minval=10, maxval=50)
up_change = math.max(close - close[1], 0)
down_change = math.max(close[1] - close, 0)
volume_adj_up = up_change * volume
volume_adj_down = down_change * volume
avg_gain_vol_adj = ta.rma(volume_adj_up, length)
avg_loss_vol_adj = ta.rma(volume_adj_down, length)
vars = if avg_loss_vol_adj != 0
avg_gain_vol_adj / avg_loss_vol_adj
else if avg_gain_vol_adj > 0
1000000000.0
else
1.0
v_rsi = 100 - (100 / (1 + vars))
plot(v_rsi, "VARSI", color.blue, display=display.pane_only)
hline(obLevel, "Overbought", color.red, linestyle=hline.style_dashed, display=display.pane_only)
hline(osLevel, "Oversold", color.green, linestyle=hline.style_dashed, display=display.pane_only)
// Long entry: VARSI crosses above oversold level
longCondition = ta.crossover(v_rsi, osLevel)
// Short entry: VARSI crosses below overbought level
shortCondition = ta.crossunder(v_rsi, obLevel)
if (longCondition)
strategy.entry("Long VARSI", strategy.long)
if (shortCondition)
strategy.entry("Short VARSI", strategy.short)
// Basic exit: opposite signal
strategy.close("Long VARSI", when=shortCondition)
strategy.close("Short VARSI", when=longCondition)
//@version=5
strategy("VARSI Divergence Strategy", overlay=true)
length = input.int(14, title="VARSI Length", minval=1)
up_change = math.max(close - close[1], 0)
down_change = math.max(close[1] - close, 0)
volume_adj_up = up_change * volume
volume_adj_down = down_change * volume
avg_gain_vol_adj = ta.rma(volume_adj_up, length)
avg_loss_vol_adj = ta.rma(volume_adj_down, length)
vars = if avg_loss_vol_adj != 0
avg_gain_vol_adj / avg_loss_vol_adj
else if avg_gain_vol_adj > 0
1000000000.0
else
1.0
v_rsi = 100 - (100 / (1 + vars))
plot(v_rsi, "VARSI", color.blue, display=display.pane_only)
hline(70, "Overbought", color.red, linestyle=hline.style_dashed, display=display.pane_only)
hline(30, "Oversold", color.green, linestyle=hline.style_dashed, display=display.pane_only)
// Simple divergence detection (conceptual, robust detection requires advanced pivot logic)
// This example looks for recent higher/lower swings in price and VARSI.
// Bullish Divergence: Price lower low, VARSI higher low
bullishDiv = close < close[1] and close[1] < close[2] and v_rsi > v_rsi[1] and v_rsi[1] > v_rsi[2]
// Bearish Divergence: Price higher high, VARSI lower high
bearishDiv = close > close[1] and close[1] > close[2] and v_rsi < v_rsi[1] and v_rsi[1] < v_rsi[2]
// Plot shapes on the chart to indicate divergence
plotshape(bullishDiv, title="Bullish VARSI Divergence", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(bearishDiv, title="Bearish VARSI Divergence", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)
if (bullishDiv)
strategy.entry("Long Divergence", strategy.long)
if (bearishDiv)
strategy.entry("Short Divergence", strategy.short)
// Basic exit after a few bars or on opposite signal
strategy.exit("Long Divergence Exit", from_entry="Long Divergence", profit=close*0.02, loss=close*0.01)
strategy.exit("Short Divergence Exit", from_entry="Short Divergence", profit=close*0.02, loss=close*0.01)
//@version=5
strategy("VARSI Mid-Line Trend Strategy", overlay=true)
length = input.int(14, title="VARSI Length", minval=1)
up_change = math.max(close - close[1], 0)
down_change = math.max(close[1] - close, 0)
volume_adj_up = up_change * volume
volume_adj_down = down_change * volume
avg_gain_vol_adj = ta.rma(volume_adj_up, length)
avg_loss_vol_adj = ta.rma(volume_adj_down, length)
vars = if avg_loss_vol_adj != 0
avg_gain_vol_adj / avg_loss_vol_adj
else if avg_gain_vol_adj > 0
1000000000.0
else
1.0
v_rsi = 100 - (100 / (1 + vars))
plot(v_rsi, "VARSI", color.blue, display=display.pane_only)
hline(50, "Mid-Line", color.gray, linestyle=hline.style_dotted, linewidth=2, display=display.pane_only)
// Long entry: VARSI crosses above 50
longCondition = ta.crossover(v_rsi, 50)
// Short entry: VARSI crosses below 50
shortCondition = ta.crossunder(v_rsi, 50)
if (longCondition)
strategy.entry("Long Mid-Line", strategy.long)
if (shortCondition)
strategy.entry("Short Mid-Line", strategy.short)
// Basic exit: opposite signal
strategy.close("Long Mid-Line", when=shortCondition)
strategy.close("Short Mid-Line", when=longCondition)
// Color background based on VARSI's position relative to 50
bgcolor(v_rsi > 50 ? color.new(color.lime, 95) : na, title="Bullish Momentum")
bgcolor(v_rsi < 50 ? color.new(color.maroon, 95) : na, title="Bearish Momentum")
To get the most from Volume-Adjusted RSI in Pinescript:
VARSI acts as a "conviction check" for momentum. Is the price movement genuinely supported by significant volume, or is it just noise? VARSI helps answer that.
The Volume-Adjusted RSI (VARSI) is a powerful and insightful momentum oscillator for Pinescript in TradingView. By integrating volume weighting into the traditional RSI calculation, it provides a more robust measure of overbought/oversold conditions, enhances the reliability of divergence signals, and offers a clearer confirmation of price trend conviction. While requiring a custom implementation and careful attention to its unique interpretation, VARSI serves as an excellent tool for traders seeking to validate momentum with underlying volume strength. By understanding its calculation, thoughtfully tuning its parameters, and integrating it strategically with price action and other technical analysis tools, you can leverage VARSI to significantly enhance your Pinescript strategies and gain a deeper understanding of true market strength.
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