Files
QuanTAlib/lib/channels/vwapbands/vwapbands.md
T
86fe32a682 SIMD Refactor: Merge simd-dev into dev (#55)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: aider (openrouter/anthropic/claude-sonnet-4) <aider@aider.chat>
Co-authored-by: Warp <agent@warp.dev>
2026-01-18 19:02:03 -08:00

12 KiB
Raw Blame History

VWAPBANDS: VWAP Bands

Overview and Purpose

VWAP Bands (VWAPBANDS) is a channel indicator that extends the Volume Weighted Average Price (VWAP) concept by adding standard deviation bands above and below the central VWAP line. This indicator combines the volume-weighted fairness concept of VWAP with statistical volatility measurements, creating dynamic support and resistance levels that reflect both price-volume relationships and market volatility.

Unlike traditional moving average-based bands, VWAPBANDS uses volume-weighted variance calculations to determine band width, making the indicator particularly sensitive to volume-driven price movements. The bands automatically adjust to market conditions while maintaining their statistical significance, providing traders with reliable levels for identifying overbought/oversold conditions and potential reversal points.

Core Concepts

  • Volume-weighted statistics: Uses volume data to weight price observations, giving more importance to high-volume periods
  • Session-based calculation: Resets calculations based on configurable time periods (daily, hourly, etc.)
  • Statistical significance: Bands represent 1 and 2 standard deviations from the volume-weighted mean
  • Dynamic adaptation: Band width adjusts automatically based on volume-weighted price variance
  • Multi-timeframe flexibility: Supports various reset intervals from minutes to months
  • Institutional relevance: Reflects the same VWAP calculations used by institutional traders

The key advantage of VWAPBANDS is its ability to combine the fairness concept of VWAP (where institutional orders are often benchmarked) with volatility-based support and resistance levels, making it particularly valuable for understanding institutional price levels and market structure.

Common Settings and Parameters

Parameter Default Function When to Adjust
Source HLC3 Price data used for VWAP calculation Use Close for end-of-period analysis, HLC3 for comprehensive price representation
Session Reset 1D Time period for VWAP calculation reset Match to trading strategy timeframe: intraday (1H, 4H), swing (1D), position (1W)
StdDev Multiplier 1.0 Distance of primary bands from VWAP in standard deviations Increase for wider bands in volatile markets, decrease for tighter levels
Show 2nd Bands True Display secondary bands at 2x multiplier distance Disable for cleaner charts, enable for additional confluence levels

Pro Tip: Use daily reset for swing trading strategies, hourly reset for intraday scalping, and weekly reset for position trading to align the indicator with your trading timeframe.

Calculation and Mathematical Foundation

Simplified explanation: VWAPBANDS calculates the volume-weighted average price from the session start, then computes the volume-weighted variance of prices around this average. Standard deviation bands are plotted at 1x and 2x the multiplier distance from VWAP.

Technical formula:

  1. VWAP = Σ(Price × Volume) / Σ(Volume)
  2. Volume-Weighted Variance = Σ(Price² × Volume) / Σ(Volume) - VWAP²
  3. Standard Deviation = √(Volume-Weighted Variance)
  4. Upper Band = VWAP + (Multiplier × Standard Deviation)
  5. Lower Band = VWAP - (Multiplier × Standard Deviation)

Detailed calculation steps:

  1. Initialize cumulative sums at session start (price×volume, volume, price²×volume)
  2. For each bar, add current values to cumulative sums if volume > 0
  3. Calculate VWAP as ratio of cumulative price×volume to cumulative volume
  4. Compute volume-weighted second moment and subtract VWAP squared for variance
  5. Take square root of variance to get standard deviation
  6. Plot bands at specified multiples of standard deviation from VWAP

🔍 Technical Note: The implementation uses session-based resets to ensure VWAP calculations align with market structure. Volume-weighted variance provides more accurate volatility measurement than simple price variance, as it reflects the actual trading intensity at different price levels.

Interpretation Details

VWAPBANDS provides multiple layers of market analysis:

  • VWAP Line Analysis:

    • Price above VWAP: Bullish bias, buyers in control above fair value
    • Price below VWAP: Bearish bias, sellers in control below fair value
    • Price oscillating around VWAP: Balanced market, fair value region
  • Band Interaction Signals:

    • Price touching upper 1σ band: Potential resistance, consider profit-taking
    • Price touching lower 1σ band: Potential support, consider accumulation
    • Price beyond 2σ bands: Extreme conditions, potential mean reversion opportunity
    • Price consistently above/below bands: Strong trend continuation signal
  • Band Width Analysis:

    • Expanding bands: Increasing volatility, larger price movements expected
    • Contracting bands: Decreasing volatility, potential breakout setup
    • Stable band width: Consistent volatility environment
  • Volume-Price Relationship:

    • High volume near bands: Increased significance of support/resistance levels
    • Low volume near bands: Potential for false breakouts or weak reversals
    • Volume expansion with band breaks: Confirmation of directional moves

Trading Applications

Mean Reversion Strategy:

  • Buy when price touches or exceeds lower 1σ band with volume confirmation
  • Sell when price reaches VWAP or upper bands
  • Use 2σ bands for extreme mean reversion opportunities
  • Set stops beyond 2σ levels to account for extended moves

Trend Following Strategy:

  • Enter long positions when price breaks above upper bands with volume
  • Enter short positions when price breaks below lower bands with volume
  • Use VWAP as dynamic support/resistance in trending markets
  • Trail stops using the opposite band or VWAP line

Institutional Level Trading:

  • Monitor price action around VWAP for institutional interest
  • Look for volume spikes when price approaches VWAP after extended moves
  • Use VWAP as benchmark for order execution efficiency
  • Identify accumulation/distribution phases based on VWAP interaction

Breakout Strategy:

  • Monitor periods of contracting bands for potential breakouts
  • Enter positions on volume-confirmed breaks beyond 1σ bands
  • Target 2σ bands for profit-taking on breakout moves
  • Use failed breakouts as contrarian signals

Signal Combinations

High-Probability Long Signals:

  • Price bounces off lower 1σ band with increasing volume
  • Price reclaims VWAP after period below with strong volume
  • Bullish divergence between price and volume at lower bands
  • Multiple timeframe VWAP alignment supporting upward bias

High-Probability Short Signals:

  • Price fails at upper 1σ band with declining volume
  • Price breaks below VWAP after period above with strong volume
  • Bearish divergence between price and volume at upper bands
  • Multiple timeframe VWAP alignment supporting downward bias

Consolidation Warnings:

  • Price oscillating between narrow bands around VWAP
  • Decreasing volume with price approaching bands
  • Multiple false breakouts beyond bands
  • Band width contracting significantly

Advanced Techniques

Multi-Timeframe Analysis:

  • Use higher timeframe VWAPBANDS for major support/resistance levels
  • Combine daily VWAP with intraday bands for precision timing
  • Look for confluence between different session VWAP levels
  • Identify key levels where multiple timeframe VWAPs converge

Volume Profile Integration:

  • Combine VWAPBANDS with volume profile for enhanced context
  • Identify high-volume nodes near VWAP levels
  • Use volume-at-price data to validate band significance
  • Monitor institutional order flow around VWAP levels

Session-Specific Analysis:

  • Analyze different session reset periods for various market conditions
  • Use overnight VWAP for gap analysis and fair value assessment
  • Apply weekly VWAP for longer-term institutional benchmarking
  • Implement monthly VWAP for portfolio rebalancing levels

Performance Profile

Operation Count (Streaming Mode, per Bar)

VWAP Bands uses cumulative sums for volume-weighted statistics:

Operation Count Cost (cycles) Subtotal
ADD/SUB 8 1 8
MUL 6 3 18
DIV 3 15 45
SQRT 1 15 15
Total 18 ~86 cycles

Breakdown:

  • Cumulative sum updates (pv, vol, pv²): 3 ADD + 3 MUL = 12 cycles
  • VWAP calculation: 1 DIV = 15 cycles
  • Variance (E[X²] - E[X]²): 1 DIV + 1 MUL + 1 SUB = 19 cycles
  • Std dev + bands: 1 SQRT + 1 MUL + 4 ADD = 22 cycles

Session reset: Adds 1 CMP per bar for reset detection (~1 cycle).

Complexity Analysis

Mode Complexity Notes
Streaming O(1) Cumulative sums with session reset
Batch O(n) Linear scan

Memory: ~48 bytes (cumulative sums for pv, vol, pv², session state)

SIMD Analysis

Optimization Applicable Notes
AVX2 vectorization Partial Cumulative sums vectorizable within session
FMA price * volume pattern
Batch parallelism Cumulative sums create dependencies

Note: Session resets create sequential boundaries that limit SIMD optimization across sessions.

Quality Metrics

Metric Score Notes
Accuracy 9/10 Volume-weighted mean is statistically optimal
Timeliness 7/10 Cumulative nature creates lag late in session
Overshoot 8/10 Volume weighting stabilizes extremes
Smoothness 7/10 Can be choppy early in session

Limitations and Considerations

  • Session dependency: Reset timing significantly affects indicator behavior and relevance
  • Volume quality: Requires accurate volume data; may be less reliable in low-volume periods
  • Lag component: VWAP calculations create some lag, especially early in sessions
  • Market structure: Most effective in liquid markets with consistent volume patterns
  • Gap handling: Overnight gaps can affect VWAP relevance at session open
  • False signals: Low-volume periods may produce unreliable band interactions

VWAPBANDS vs. Bollinger Bands:

  • VWAPBANDS: Volume-weighted center line with volume-weighted variance
  • Bollinger Bands: Simple moving average center with price-based standard deviation

VWAPBANDS vs. Keltner Channels:

  • VWAPBANDS: VWAP-based with statistical variance measurements
  • Keltner Channels: EMA-based with ATR-derived band width

VWAPBANDS vs. Standard VWAP:

  • VWAPBANDS: Adds volatility context with standard deviation bands
  • Standard VWAP: Single line without volatility or support/resistance context

Best Practices

Parameter Optimization:

  • Match session reset to trading strategy timeframe
  • Adjust multiplier based on asset volatility characteristics
  • Test different source prices (close vs. HLC3) for optimal results
  • Consider market hours and session boundaries for reset timing

Risk Management:

  • Use bands for position sizing (larger positions near support bands)
  • Set stops beyond 2σ levels to avoid normal volatility whipsaws
  • Monitor volume confirmation for all band interaction signals
  • Avoid trading during low-volume periods when bands may be unreliable

Market Context:

  • Consider overall market regime (trending vs. ranging)
  • Account for news events and earnings that may affect volume patterns
  • Monitor correlation with institutional trading patterns
  • Adjust expectations based on market volatility environment

References

  • Harris, L. (2003). Trading and Exchanges: Market Microstructure for Practitioners. Oxford University Press.
  • Berkowitz, S. A. (1993). The Advantages of Volume Weighted Average Price Trading. Journal of Portfolio Management.