Volume IndicatorPine Script v6

Volume Weighted Average Price Pine Script — Complete TradingView Guide

The Volume Weighted Average Price (VWAP) Pine Script indicator calculates the average price of a security weighted by traded volume, providing institutional traders and retail traders with a real-time benchmark for fair value during a trading session. In Pine Script v6, the built-in function ta.vwap(source, anchor, stdev_mult) computes VWAP with an anchor that resets at the start of each session — defaulting to daily anchor ("1D"). VWAP is plotted directly on the price chart as an overlay, accompanied by optional standard deviation bands that mark statistically significant deviations from the volume-weighted mean. VWAP is the primary intraday benchmark used by institutional desks, algorithmic traders, and day traders on stocks, crypto, forex, and futures. This complete guide covers the Pine Script code, parameter tuning, and proven VWAP trading strategies you can apply in TradingView today.

What Is the Volume Weighted Average Price (VWAP)?

The Volume Weighted Average Price (VWAP) is a volume-weighted indicator that calculates the cumulative average price of a security weighted by traded volume, used to identify institutional fair value during a trading session. VWAP was developed and popularized in the 1980s by institutional trading desks seeking a benchmark to evaluate order execution quality. It became widely used as a performance benchmark when Berkshire Hathaway and large pension funds began measuring whether their trades were executed above or below VWAP.

The core VWAP formula is:

VWAP = Σ(Typical Price × Volume) ÷ Σ(Volume)
Typical Price = (High + Low + Close) ÷ 3

Where Typical Price (also written as hlc3 in Pine Script) is the average of the high, low, and closing price for each bar, and Volume is the number of contracts or shares traded during that bar. The formula accumulates from the anchor point (e.g., the market open) and resets at the start of each new session.

VWAP applies to all major asset classes and trading environments:

  • Equities (stocks and ETFs): VWAP is the primary intraday benchmark for institutional order execution on NYSE, NASDAQ, and global exchanges
  • Futures (ES, NQ, CL, GC): widely used by algorithmic traders on 1M–15M charts to time entries relative to the session average
  • Cryptocurrency (BTC, ETH, altcoins): 24/7 markets use weekly-anchored VWAP since there is no daily session open
  • Forex: less common due to decentralized volume data, but used on major pairs where exchange volume is available

Best timeframes for VWAP:

  • 1M–5M charts: optimal for scalping and high- frequency day trading on equities and futures
  • 15M–1H charts: best for intraday swing trades within a single session
  • Daily charts with weekly anchor: used for swing traders evaluating multi-day price structure against the weekly volume-weighted mean

VWAP is less useful on timeframes above 1H for daily-anchored settings because the indicator resets each session and does not carry information across session boundaries. For multi-day price analysis, a moving average like EMA 20 or SMA 50 is more appropriate. The standard deviation bands plotted above and below VWAP (±1σ and ±2σ) mark statistically extreme deviations from the session mean and are used as dynamic support and resistance levels by experienced traders.

VWAP Pine Script Code Example

The following Pine Script v6 code calculates the Volume Weighted Average Price using the built-in ta.vwap(hlc3, anchor, stdev_mult) function, anchored to the daily session and plotted with upper and lower standard deviation bands. To use it in TradingView, open the Pine Script Editor from the bottom toolbar, paste the code, click Save, then click Add to chart — the VWAP line and bands will appear directly on the price chart as an overlay.

Pine Script v6
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Pineify

//@version=6
indicator(title="Volume Weighted Average Price", overlay=true, max_labels_count=500)

// VWAP — anchored daily, with upper and lower standard deviation bands
p_ta_vwap(series float source, simple string anchor_timeframe, series float stdev_mult) =>
    anchor = timeframe.change(anchor_timeframe)
    [vwap, upper, lower] = ta.vwap(source, anchor, stdev_mult)
    [vwap, upper, lower]

[p_ind_1_vwap, p_ind_1_upper, p_ind_1_lower] = p_ta_vwap(hlc3, "1D", 1) // VWAP anchored to daily session

// Plot VWAP line and standard deviation bands
plot(p_ind_1_vwap, title="VWAP", color=color.rgb(41, 98, 255, 0), linewidth=1)
p_ind_1_upper_plot = plot(p_ind_1_upper, title="VWAP - Upper Band", color=color.rgb(76, 175, 80, 0), linewidth=1)
p_ind_1_lower_plot = plot(p_ind_1_lower, title="VWAP - Lower Band", color=color.rgb(76, 175, 80, 0), linewidth=1)
fill(p_ind_1_upper_plot, p_ind_1_lower_plot, color=color.rgb(76, 175, 80, 95), title="VWAP - Background")
Volume Weighted Average Price indicator Pine Script code example in TradingView

VWAP Pine Script Parameters

The ta.vwap(source, anchor, stdev_mult) function accepts three parameters. The table below lists each parameter, its default value, description, and recommended ranges for different trading styles.

ParameterDefault ValueDescriptionRecommended Range
sourcehlc3Price series used for VWAP calculation. Standard convention is the typical price (high + low + close) / 3hlc3 (default, standard); close for simplified calculations; ohlc4 for smoother curves
anchor"1D"The timeframe string at which VWAP resets. A boolean true triggers a reset; passing a timeframe string resets at each new period"1D" (daily, equities/futures); "1W" (weekly, crypto); "1M" (monthly, macro swing trading)
stdev_mult1Standard deviation multiplier for the upper and lower bands plotted around VWAP. Controls band width0.5–1.0 (tight, low-volatility assets); 1.0 (default); 2.0 (crypto/volatile stocks); 3.0 (extreme outlier detection)
Tuning scenarios:
  • Day trading equities (1M–5M): use anchor "1D", stdev_mult 1 — tracks the official session VWAP that institutional desks use
  • Crypto intraday (15M–1H): use anchor "1W", stdev_mult 2 — wider bands account for crypto's higher volatility versus equities
  • Swing trading (Daily charts): use anchor "1M", stdev_mult 1.5 — monthly VWAP acts as a macro fair-value reference across 4–6 weeks

VWAP Trading Strategies

Strategy 1: VWAP Pullback — Buy the Dip to Fair Value

Market environment: Trending intraday (bullish bias) — works best when price has opened above VWAP and institutional demand is absorbing selling pressure at the VWAP level. Combine with RSI to time the pullback entry precisely.

Entry conditions (long):

  1. Price is above VWAP at the session open, confirming bullish institutional bias
  2. Price pulls back to touch or cross below VWAP by less than 0.1% during the session
  3. RSI(14) is between 40–50 — neutral zone confirms the pullback is not a trend reversal
  4. Enter long at the open of the next 5M bar after price closes back above VWAP

Exit conditions:

  1. Target: VWAP upper band (VWAP + 1σ) — first profit-taking zone
  2. Stop-loss: close below the VWAP lower band (VWAP − 1σ), signaling session bias has flipped bearish

Strategy 2: VWAP Band Fade — Mean Reversion at Extremes

Market environment: Range-bound / low-volatility sessions — most effective on choppy, non-trending days when price oscillates between the VWAP bands. Combine with MFI (Money Flow Index) to confirm volume exhaustion.

Entry conditions (long — fade the lower band):

  1. Price touches or closes below VWAP − 1σ band
  2. MFI(14) is below 20 — volume-weighted oversold confirmation
  3. The prior 3 bars show declining bearish volume (volume is shrinking as price falls)
  4. Enter long at next bar open with a limit order near VWAP − 1σ

Exit conditions:

  1. Target: VWAP midline — mean reversion to fair value, typically 60–70% of the ±1σ range
  2. Stop-loss: close below VWAP − 2σ — extreme deviation signals a trending move rather than a fade

Strategy 3: VWAP as Trend Filter with EMA Confirmation

Market environment: Trending (intraday momentum) — uses VWAP as a macro session filter and EMA 9 as a micro entry trigger. Works on 5M–15M charts for futures (ES, NQ) and large-cap equities.

Entry conditions (long):

  1. Price is above VWAP — macro session trend is bullish
  2. EMA 9 crosses above EMA 21 on the current timeframe — micro momentum aligns with the macro trend
  3. Volume on the crossover bar is above the 20-bar average volume — confirms institutional participation
  4. Enter long at next bar open after all three conditions are met

Exit conditions:

  1. Price closes below VWAP — session bias has flipped, exit immediately
  2. EMA 9 crosses below EMA 21 — momentum reversal, scale out of position
Disclaimer: The trading strategies described above are for educational purposes only. They do not constitute investment advice or a recommendation to buy or sell any financial instrument. Past performance of any indicator or strategy does not guarantee future results. Always conduct your own research and consult a licensed financial advisor before trading.

How to Generate VWAP Pine Script in Pineify

Pineify generates production-ready Pine Script v6 code for the VWAP indicator in seconds — no coding knowledge required.

  1. 1

    Open Pineify at pineify.app

    Sign up for a free account or log in to access the indicator builder with 235+ built-in indicators.

  2. 2

    Click "Add Indicator" and search for VWAP

    Select "Volume Weighted Average Price" from the indicator library. The indicator is pre-configured with the daily anchor and standard deviation bands.

  3. 3

    Describe your strategy and configure VWAP settings

    Set the anchor timeframe ("1D" for equities, "1W" for crypto), standard deviation multiplier, and add optional EMA or RSI confirmation indicators for your strategy.

  4. 4

    Copy the generated Pine Script v6 code

    Pineify generates a complete, runnable VWAP script with your exact settings. Click "Copy" to copy it to your clipboard.

  5. 5

    Adjust and paste into TradingView Pine Script Editor

    Open the Pine Script Editor on TradingView, paste the code, click Save, and click "Add to chart" to see your VWAP indicator with bands overlaid on the price chart.

Generate VWAP Pine Script for Free

VWAP Pine Script — Frequently Asked Questions

Related Pine Script Indicators

Explore other popular Pine Script indicators available in Pineify:

Ready to Generate Your VWAP Indicator?

Pineify generates production-ready Pine Script v6 code for VWAP and 235+ other indicators. Free to get started.

Get Started Free