OPEN-SOURCE SCRIPT

VWAP Composites

191
📊 VWAP Composite - Advanced Multi-Period Volume Weighted Average Price Indicator

═══════════════════════════════════════════════════════════════════

🎯 OVERVIEW

VWAP Composite is an advanced volume-weighted average price (VWAP) indicator that goes beyond traditional single-period VWAP calculations by offering composite multi-period analysis and unprecedented customization. This indicator solves a common problem traders face: traditional VWAP resets at arbitrary intervals (session start, day, week), but significant price action and volume accumulation often spans multiple periods. VWAP Composite allows you to anchor VWAP calculations to any timeframe—or combine multiple periods into a single composite VWAP—giving you a true representation of average price weighted by volume across the exact periods that matter to your analysis.

═══════════════════════════════════════════════════════════════════

⚙️ HOW IT WORKS - CALCULATION METHODOLOGY

📌 CORE VWAP CALCULATION
The indicator calculates VWAP using the standard volume-weighted formula:
• Typical Price = (High + Low + Close) / 3
• VWAP = Σ(Typical Price × Volume) / Σ(Volume)

This calculation is performed across user-defined time periods, ensuring each bar's contribution to the average is proportional to its trading volume.

📌 STANDARD DEVIATION BANDS
The indicator calculates volume-weighted standard deviation to measure price dispersion around the VWAP:
• Variance = Σ[(Typical Price - VWAP)² × Volume] / Σ(Volume)
• Standard Deviation = √Variance
• Upper Band = VWAP + (StdDev × Multiplier)
• Lower Band = VWAP - (StdDev × Multiplier)

These bands help identify overbought/oversold conditions relative to the volume-weighted mean, with high-volume price excursions having greater impact on band width than low-volume moves.

📌 COMPOSITE PERIOD METHODOLOGY (Auto Mode)
Unlike traditional VWAP that resets at fixed intervals, Auto Mode creates composite VWAPs by combining the current period with N previous periods:
• Period Span = 1: Current period only (standard VWAP behavior)
• Period Span = 2: Current period + 1 previous period combined
• Period Span = 3: Current period + 2 previous periods combined
• And so on...

Example: A 3-period Weekly composite VWAP calculates from the start of 2 weeks ago through the current week's end, creating a single VWAP that represents 21 days of continuous price and volume data. This provides context about where price stands relative to the volume-weighted average over multiple weeks, not just the current week.

═══════════════════════════════════════════════════════════════════

🔧 KEY FEATURES & ORIGINALITY

✅ DUAL OPERATING MODES

1️⃣ MANUAL MODE (5 Independent VWAPs)
Define up to 5 separate VWAP calculations with custom start/end times:
• Perfect for anchoring VWAP to specific events (earnings, Fed announcements, major reversals)
• Each VWAP has independent color settings for lines and deviation band backgrounds
• Individual control over calculation extension and visual extension (explained below)
• Useful for tracking multiple institutional accumulation/distribution zones simultaneously

2️⃣ AUTO MODE (Composite Period VWAP)
Automatically calculates VWAP across combined time periods:
• Supported periods: Daily, Weekly, Monthly, Quarterly, Yearly
• Configurable period span (1-20 periods)
• Always up-to-date, recalculates on each new bar
• Ideal for systematic analysis across consistent timeframes

✅ DUAL EXTENSION SYSTEM (Manual Mode Innovation)

Most VWAP indicators only offer "on/off" for extending calculations. This indicator provides two distinct extension options:

🔹 EXTEND CALCULATION TO CURRENT BAR
When enabled, continues including new bars in the VWAP calculation after the defined end time. The VWAP value updates dynamically as new volume enters the market.
Use case: You anchored VWAP to a major low 3 weeks ago. You want the VWAP to continue evolving with new volume data to track ongoing institutional positioning.

🔹 EXTEND VISUAL LINE ONLY
When enabled (and calculation extension is disabled), projects the "frozen" VWAP value forward as a reference line. The VWAP value remains fixed at what it was at the end time, but the line and deviation bands visually extend to current price.
Use case: You want to see how price is behaving relative to the VWAP that existed at a specific point in time (e.g., "Where is price now vs. the 5-day VWAP that existed at last Friday's close?").

This dual system gives you unprecedented control over whether you're tracking a "living" VWAP that incorporates new data or using historical VWAP levels as static reference points.

✅ CUSTOMIZABLE STANDARD DEVIATION BANDS
• Adjustable multiplier (0.1 to 5.0)
• Independent background colors with opacity control for each VWAP
• Dashed band lines for easy visual distinction from main VWAP
• Bands extend when visual extension is enabled, maintaining zone visibility

✅ COMPREHENSIVE LABELING SYSTEM
Each VWAP displays:
• Current VWAP value
• Upper deviation band value (High)
• Lower deviation band value (Low)
• Extension status indicator (Calc Extended / Visual Extended)
• Color-coded for quick identification

═══════════════════════════════════════════════════════════════════

📖 HOW TO USE THIS INDICATOR

🎯 SCENARIO 1: EVENT-ANCHORED VWAP (Manual Mode)
Use case: A stock gaps down 15% on earnings and you want to track where institutions are positioning during the recovery.

Setup:
1. Switch to Manual Mode
2. Enable VWAP 1
3. Set Start Time to the earnings gap bar
4. Set End Time to current time (or leave far in future)
5. Enable "Extend Calculation to Current Bar"
6. Watch how price respects the VWAP as a dynamic support/resistance

Interpretation:
• Price above VWAP = buyers in control since the event
• Price testing VWAP from above = potential support
• Volume-weighted standard deviation bands show normal price range
• Price outside bands = potential exhaustion/mean reversion setup

🎯 SCENARIO 2: MULTI-WEEK INSTITUTIONAL ACCUMULATION ZONE (Auto Mode)
Use case: You trade swing setups and want to identify where institutions have been accumulating over the past 3 weeks.

Setup:
1. Switch to Auto Mode
2. Select "Weekly" period type
3. Set Period Span to 3
4. Enable standard deviation bands

Interpretation:
• 3-week composite VWAP shows the true average institutional entry
• Price bouncing off VWAP repeatedly = strong support (institutions defending their average)
• Price breaking below VWAP on high volume = potential distribution
• Deviation bands contracting = consolidation; expanding = volatility increase

🎯 SCENARIO 3: COMPARING MULTIPLE TIME HORIZONS (Manual Mode)
Use case: You want to see short-term vs medium-term vs long-term VWAP alignments.

Setup:
1. Switch to Manual Mode
2. VWAP 1: Last 5 trading days (blue)
3. VWAP 2: Last 10 trading days (orange)
4. VWAP 3: Last 20 trading days (purple)
5. Enable "Extend Calculation" for all
6. Set different background colors for visual separation

Interpretation:
• All VWAPs aligned upward = strong trend across all timeframes
• Price between VWAPs = finding equilibrium between different trader timeframes
• Short-term VWAP crossing long-term VWAP = momentum shift
• Price rejecting at higher-timeframe VWAP = that timeframe's traders defending their average

🎯 SCENARIO 4: HISTORICAL VWAP REFERENCE LEVELS (Manual Mode)
Use case: You want to see where the 1-month VWAP was at each month-end as static reference levels.

Setup:
1. Switch to Manual Mode
2. VWAP 1: Set to last month's start/end dates
3. VWAP 2: Set to 2 months ago start/end dates
4. VWAP 3: Set to 3 months ago start/end dates
5. Disable "Extend Calculation"
6. Enable "Extend Visual Line Only"

Interpretation:
• Each VWAP represents the volume-weighted average for that complete month
• These become static support/resistance levels
• Price returning to old monthly VWAPs = institutional memory/gap fill behavior
• Useful for identifying longer-term value areas

═══════════════════════════════════════════════════════════════════

🎨 CUSTOMIZATION OPTIONS

GENERAL SETTINGS
• Show/hide labels
• Line style: Solid, Dashed, or Dotted
• Standard deviation multiplier (impacts band width)
• Toggle standard deviation bands on/off

MANUAL MODE (Per VWAP)
• Custom start and end times
• Line color picker
• Background color picker (with transparency control)
• Extend calculation option
• Extend visual option
• Show/hide individual VWAPs

AUTO MODE
• Period type selection (Daily/Weekly/Monthly/Quarterly/Yearly)
• Period span (1-20 periods)
• Line color
• Background color (with transparency control)

═══════════════════════════════════════════════════════════════════

💡 TRADING APPLICATIONS

✓ Mean Reversion: Use deviation bands to identify stretched prices likely to return to VWAP
✓ Trend Confirmation: Price sustained above VWAP = bullish bias; below = bearish bias
✓ Support/Resistance: VWAP often acts as dynamic S/R, especially on higher volume periods
✓ Institutional Positioning: Multi-day/week VWAPs show where large players have established positions
✓ Entry Timing: Wait for pullbacks to VWAP in trending markets
✓ Stop Placement: Use VWAP ± standard deviation as volatility-adjusted stop levels
✓ Breakout Confirmation: Breakouts from consolidation with price reclaiming VWAP = stronger signal
✓ Multi-Timeframe Analysis: Compare short vs long-period VWAPs to gauge momentum alignment

═══════════════════════════════════════════════════════════════════

⚠️ IMPORTANT NOTES

• The indicator redraws on each bar to maintain accurate visual representation (uses `barstate.islast`)
• Maximum lookback is limited to 5000 bars for performance optimization
• Time range calculations work across all timeframes but are most effective on intraday to daily charts
• Standard deviation bands assume volume-weighted distribution; extreme events may violate assumptions
• Auto mode always calculates to current bar; use Manual mode for fixed historical periods

═══════════════════════════════════════════════════════════════════

This indicator is open-source. Feel free to examine the code, learn from it, and adapt it to your needs.

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。