Logo
OFFLINEPIXEL
/ pinescript-strategies / pine-script-volume-adjusted-rsi

$ Pinescript Volume-Adjusted RSI (VARSI)

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.

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 Volume-Adjusted RSI (VARSI)?

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:

  • More robust overbought/oversold readings: VARSI might stay in overbought/oversold territory longer or reach it more decisively when volume confirms the move.
  • Stronger divergence signals: Divergences between price and VARSI gain more credibility when the volume component underscores the lack of conviction.
  • Enhanced trend confirmation: Momentum supported by volume is considered more sustainable.
02

Components and Calculation

The calculation of Volume-Adjusted RSI builds upon the traditional RSI formula by introducing a volume weighting step. Here's a breakdown:

  1. Price Change Calculation:
    * `Up_Change = max(close - close[1], 0)` (positive price difference, 0 if negative)
    * `Down_Change = max(close[1] - close, 0)` (positive price difference on down days, 0 if up)
  2. Volume-Adjusted Price Change: Each price change is multiplied by the current bar's volume.
    * `Volume_Adj_Up = Up_Change * volume`
    * `Volume_Adj_Down = Down_Change * volume`
  3. Average Volume-Adjusted Gains and Losses: These volume-adjusted changes are smoothed using a Reinforced Moving Average (`ta.rma`), similar to how RSI smooths its gains and losses.
    * `Avg_Gain_Vol_Adj = ta.rma(Volume_Adj_Up, Length)`
    * `Avg_Loss_Vol_Adj = ta.rma(Volume_Adj_Down, Length)`
    (Where `Length` is the RSI period, typically 14)
  4. Volume-Adjusted Relative Strength (VARS): This is the ratio of the average volume-adjusted gain to the average volume-adjusted loss.
    * `VARS = Avg_Gain_Vol_Adj / Avg_Loss_Vol_Adj`
    * Important: Handle division by zero. If `Avg_Loss_Vol_Adj` is 0:
    * If `Avg_Gain_Vol_Adj` is also 0, `VARS` is indeterminate (can default to 0 or 1).
    * If `Avg_Gain_Vol_Adj` is > 0, `VARS` is considered infinite (leading to VARSI = 100).
  5. Volume-Adjusted RSI (VARSI): The final VARSI value is calculated using the standard RSI formula:
    `VARSI = 100 - (100 / (1 + VARS))`
03

Basic Volume-Adjusted RSI (VARSI) Implementation in Pinescript

pine-script@terminal
//@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")
$ ✓ Compiled successfully
04

Volume Power

Volume Power

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.

05

Practical Volume-Adjusted RSI (VARSI) Trading Strategies

06

1. Overbought/Oversold Signals with Volume Conviction

pine-script@terminal
//@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)
$ ✓ Compiled successfully
07

2. Divergence (Enhanced Reversal Signal)

pine-script@terminal
//@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)
$ ✓ Compiled successfully
08

3. Trend Confirmation with VARSI's Mid-Line

pine-script@terminal
//@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")
$ ✓ Compiled successfully
09

Optimizing Volume-Adjusted RSI (VARSI) Performance

To get the most from Volume-Adjusted RSI in Pinescript:

  • Parameter Tuning: The `length` parameter (commonly 14) directly impacts VARSI's sensitivity. Shorter lengths make it more reactive but potentially noisy. Longer lengths provide a smoother reading but with more lag. Experiment to find a balance for your asset and timeframe.
  • Focus on Divergence: VARSI's key strength lies in its ability to confirm divergences with price due to the added volume component. These are often the most powerful and actionable signals.
  • Combine with Price Action: Always confirm VARSI signals with price action. An overbought VARSI signal is stronger if price also forms a bearish reversal candlestick pattern or hits a resistance level.
  • Volume Data Quality: VARSI's effectiveness is highly dependent on accurate and reliable volume data. Ensure the asset you are trading has consistent volume reporting.
  • Adaptive Levels: While 70/30 are standard for RSI, the "overbought" and "oversold" levels for VARSI might need slight adjustment based on the asset's typical behavior and the impact of volume.
  • Use as a Filter: VARSI can be used as a filter for other strategies. For example, only take long entries if VARSI is above 50 or showing bullish divergence.
10

Conviction Check

Conviction Check

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.

11

Common Volume-Adjusted RSI (VARSI) Pitfalls

  • Lag: Despite being volume-adjusted, VARSI is still a lagging indicator. It will confirm momentum shifts after they have already begun.
  • Whipsaws in Choppy Markets: In highly volatile and non-trending (choppy) markets, VARSI can generate frequent crossovers and enter/exit overbought/oversold zones frequently, leading to false signals.
  • Volume Data Consistency: If volume data for an asset is inconsistent, sparse, or manipulated, VARSI's readings will be unreliable.
  • Not a Standalone Indicator: VARSI provides valuable insights but should never be used in isolation. It works best as a confirming or filtering indicator within a broader trading strategy.
  • Interpretation Complexity: For beginners, understanding the nuances of volume-adjusted momentum might be more challenging than a simple price-based RSI.
12

Conclusion

Conclusion

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.

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