Volume Weighted RSI [NASAlgoTrading]Volume Weighted RSI
1. Overview
This script is a specialized technical indicator for TradingView that combines two popular concepts: Volume-Weighted Average Price (VWAP) and the Relative Strength Index (RSI). The result is a volume-sensitive momentum oscillator that highlights overbought and oversold conditions while also detecting regular bearish and bullish divergences between price and the oscillator.
The indicator is intended for educational and informational purposes to demonstrate how volume-weighting can be applied to traditional momentum analysis and how divergence detection can be implemented in Pine Script. It is not a trading system or a source of financial advice.
2. Key Components & Logic
A. Volume-Weighted RSI Core
Calculation: The script first computes the VWAP (Volume-Weighted Average Price) of the closing price, then applies a standard RSI calculation to that VWAP value.
Formula: RSI_VWAP = ta.rsi(ta.vwap(close), RSI_VWAP_length)
Purpose: By using VWAP instead of the raw closing price, the oscillator places greater emphasis on periods of higher trading volume, theoretically providing a more "informed" momentum reading.
B. Overbought & Oversold Zones
Inputs: Users can set custom levels for:
RSI OVERBOUGHT (default: 80)
RSI OVERSOLD (default: 20)
Visuals:
The oscillator line is plotted in red when above overbought, green when below oversold, and cyan when in the neutral zone.
The background between the oscillator line and the overbought/oversold levels is filled with red (overbought) or lime (oversold) to highlight extreme conditions.
C. Automated Divergence Detection
Function: The script automatically detects regular bearish and regular bullish divergences between price action and the Volume-Weighted RSI.
Bearish Divergence: Price makes a higher high, but the oscillator makes a lower high (warning of potential downward reversal).
Bullish Divergence: Price makes a lower low, but the oscillator makes a higher low (warning of potential upward reversal).
Detection Method: Uses a loopback period (DIV LOOPBACK PERIOD, default: 90 bars) to identify local peaks and troughs in both price and the oscillator, then compares their relative positions.
Visuals: When a divergence is detected, the script plots a "BEAR" (red, label down) or "BULL" (green, label up) label at the corresponding oscillator peak or trough.
Alerts: Built-in alertcondition() calls for both bearish and bullish divergences.
D. Pivot Points (Optional)
Function: The script can also display pivot points on the oscillator (local highs and lows marked as "PIVOT").
Input: HIDE PIVOTS (default: false) – when disabled, pivots are shown; when enabled, they are hidden.
E. Label & Background Customization
SHORT LABELS: When enabled, removes the text from divergence and pivot labels (only the visual marker remains).
Background Coloring Options: The script includes commented or conditional background coloring logic that can be enabled to highlight divergence zones or pivot points on the chart.
3. User Inputs (Customization)
All settings are accessible in the script's "Settings" dialog box.
Input Description Default
RSI OVERBOUGHT Overbought threshold level for the oscillator. 80
RSI VOLUME WEIGHTED AVERAGE PRICE Toggle for the VWAP-based RSI calculation (currently fixed to true). true
RSI LENGTH Lookback period for the RSI calculation. 17
RSI OVERSOLD Oversold threshold level for the oscillator. 20
HIDE PIVOTS When true, hides pivot markers on the oscillator. false
SHORT LABELS When true, removes text from divergence/pivot labels. false
DIV LOOPBACK PERIOD Number of bars to look back for detecting pivot points and divergences. 90
4. How to Use
This indicator is designed for analysis and study, not as a standalone trading system. To use it effectively:
Understand the Core: Observe how the Volume-Weighted RSI behaves compared to a standard RSI. Notice how volume spikes influence the oscillator's movement.
Identify Extremes: When the oscillator enters the overbought (above 80) or oversold (below 20) zones, it suggests the volume-weighted price momentum may be stretched. However, extremes alone are not signals – they indicate potential conditions, not certain reversals.
Watch for Divergences: Regular divergences are the primary signal from this script. When a divergence is detected:
Do not act immediately. Wait for additional confirmation (e.g., a trendline break, a candlestick pattern, or a crossover of the oscillator back through the oversold/overbought level).
Divergences can sometimes persist for multiple bars; they are warnings of waning momentum, not guarantees of reversal.
Adjust Parameters: The default settings (RSI length 17, overbought 80, oversold 20) work for many assets and timeframes, but you may need to adjust them based on volatility. Shorter RSI lengths and tighter overbought/oversold levels generate more signals (and more false signals).
Paper Trade First: Always test the indicator in a simulated environment before using it with real capital.
5. Compliance & Transparency
No Financial Advice: This script is strictly for educational and informational purposes. It does not provide financial advice, trading recommendations, or guarantees. All trading decisions are your own responsibility.
Original Work: The code represents the concepts of VWAP, RSI, and divergence detection are standard, the specific implementation (combining VWAP with RSI into a single oscillator, the custom divergence logic using highestbars()/lowestbars(), and the labeling system) is original. The script is published under the Mozilla Public License 2.0.
6. Technical Notes & Limitations
Version: Written in Pine Script v5. Future updates may convert it to v6 for long-term compatibility.
Repainting Warning: The divergence detection logic uses ta.highestbars() and ta.lowestbars(), which look back a fixed number of bars. As new bars form, the identification of pivots and divergences may change slightly until enough confirmation bars exist. This is not a repainting issue but a characteristic of real-time pivot detection . Divergence labels appear on the bar where the condition is confirmed and do not repaint historical bars.
Labels: The script creates labels for divergences and pivots. On charts with many bars, this can lead to a large number of label objects. The script uses label.new() without an explicit limit, so on very long charts or low timeframes, performance may degrade. Users can mitigate this by increasing the "Maximum labels count" in the indicator's settings or by reducing the loopback period.
VWAP Behavior: VWAP is a cumulative volume-weighted average. On longer timeframes or with very large datasets, VWAP values can become "sticky" and slow to respond. This is by design and reflects the volume-weighting concept.
Non-Standard Charts: This indicator is intended for use on standard bar charts (candles, bars, line). Using it on Heikin Ashi, Renko, or other non-standard chart types may produce misleading results.
7. Credits & Open Source
License: This script is published under the Mozilla Public License 2.0. You are free to use, modify, and share this code for non-commercial purposes, provided you retain the original license and attribution.
No Hidden Code: The script is fully open-source. All calculations are visible and can be inspected by any user. No external dependencies, private keys, or hidden functions are included.
Pine Script® indicator






















