Pine Script VWAP (Daily)

Master this indispensable intraday indicator in TradingView's Pine Script, relied upon by institutional traders for identifying fair value, optimal entry/exit points, and measuring market strength.

Last Updated on: Expertise: Intermediate

What is VWAP (Daily)?

VWAP (Volume Weighted Average Price) is a crucial benchmark used by institutional traders and market makers to determine the average price of an asset, adjusted for its trading volume, throughout the trading day. Unlike a simple moving average, VWAP gives more weight to prices at which more volume was traded, making it a more accurate representation of the true average price participants paid for the asset.

The "Daily" aspect is critical: VWAP resets at the beginning of each trading session, accumulating data only for that specific day. This makes it an intraday indicator, primarily used for:

In Pine Script, the daily VWAP is a highly utilized tool for short-term trading strategies, providing actionable insights into market sentiment and price efficiency.

Components and Calculation

The calculation of VWAP is cumulative throughout the trading day and resets at the start of each new day:

  1. Typical Price (TP): For each bar (e.g., each minute, 5-minute, or 15-minute bar within the day), calculate its typical price:
    `TP = (High + Low + Close) / 3`
  2. TP * Volume (TPV): Multiply the typical price of the bar by its volume:
    `TPV = TP * Volume`
  3. Cumulative TPV: Sum the `TPV` values from the beginning of the trading day up to the current bar.
    `Cumulative TPV = Sum(TPV) for the day`
  4. Cumulative Volume: Sum the `Volume` values from the beginning of the trading day up to the current bar.
    `Cumulative Volume = Sum(Volume) for the day`
  5. VWAP Formula: Divide the Cumulative TPV by the Cumulative Volume.
    `VWAP = Cumulative TPV / Cumulative Volume`

Crucially, all these cumulative sums reset to zero at the start of every new trading day, making VWAP a powerful intraday tool.

Basic Daily VWAP Implementation in Pine Script

Pine Script v5 provides a convenient built-in function `ta.vwap()` for calculating VWAP. It automatically handles the daily reset when used on intraday timeframes.


//@version=5
indicator("My Daily VWAP", overlay=true, timeframe="D") // overlay=true to plot on price chart. timeframe="D" is key for daily reset.

// Calculate Daily VWAP using the built-in function
// ta.vwap() automatically handles the typical price (hlc3) and volume, and resets daily.
dailyVwap = ta.vwap(close, volume) // By default, `ta.vwap` uses `hlc3` for the source if not specified.

// Plot the VWAP line
plot(dailyVwap, title="Daily VWAP", color=color.purple, linewidth=2)

// Optional: Add Standard Deviation Bands around VWAP (similar to Bollinger Bands)
// These are often called VWAP Bands or Standard Deviation Bands.
// They help identify significant deviations from the daily average price.
stdDevLength = input.int(20, title="StdDev Lookback (for VWAP Bands)", minval=1)
stdDevMultiplier1 = input.float(1.0, title="StdDev Multiplier 1", minval=0.1, step=0.1)
stdDevMultiplier2 = input.float(2.0, title="StdDev Multiplier 2", minval=0.1, step=0.1)

// Custom VWAP logic with daily reset
var float sum_tp_volume = 0.0
var float sum_volume = 0.0
var float sum_sq_diff_volume = 0.0

if ta.change(time("D"))
    sum_tp_volume := 0.0
    sum_volume := 0.0
    sum_sq_diff_volume := 0.0

tp = (high + low + close) / 3
sum_tp_volume := sum_tp_volume + (tp * volume)
sum_volume := sum_volume + volume

currentDailyVwap = sum_volume != 0 ? sum_tp_volume / sum_volume : dailyVwap

if not na(currentDailyVwap) and volume > 0
    sum_sq_diff_volume := sum_sq_diff_volume + (math.pow(tp - currentDailyVwap, 2) * volume)

stdDevVwap = sum_volume != 0 ? math.sqrt(sum_sq_diff_volume / sum_volume) : 0.0

upperBand1 = currentDailyVwap + (stdDevVwap * stdDevMultiplier1)
lowerBand1 = currentDailyVwap - (stdDevVwap * stdDevMultiplier1)
upperBand2 = currentDailyVwap + (stdDevVwap * stdDevMultiplier2)
lowerBand2 = currentDailyVwap - (stdDevVwap * stdDevMultiplier2)

// Plot VWAP Bands
plot(upperBand1, title="Upper Band 1", color=color.new(color.blue, 50), linewidth=1, style=plot.style_stepline)
plot(lowerBand1, title="Lower Band 1", color=color.new(color.blue, 50), linewidth=1, style=plot.style_stepline)
plot(upperBand2, title="Upper Band 2", color=color.new(color.navy, 70), linewidth=1, style=plot.style_stepline)
plot(lowerBand2, title="Lower Band 2", color=color.new(color.navy, 70), linewidth=1, style=plot.style_stepline)

// Fill between bands for visual clarity
fill(upperBand1, lowerBand1, color.new(color.blue, 95))
fill(upperBand2, lowerBand1, color.new(color.navy, 98))
Intraday Focus: Remember, Daily VWAP resets each session. It's a key tool for understanding price performance relative to volume for *that specific day*.

Practical Daily VWAP Trading Strategies

1. Mean Reversion to VWAP

Price often tends to revert to the VWAP, especially in range-bound or consolidating intraday markets. Traders can fade moves away from VWAP, expecting a return to the average.


//@version=5
strategy("VWAP Mean Reversion Strategy", overlay=true, initial_capital=10000)

// Daily VWAP (auto-resets)
dailyVwap = ta.vwap(close, volume)
plot(dailyVwap, "Daily VWAP", color=color.purple, linewidth=2)

// VWAP Bands for mean reversion zones (manual daily reset logic)
var float sum_tp_volume = 0.0
var float sum_volume = 0.0
var float sum_sq_diff_volume = 0.0

if ta.change(time("D"))
    sum_tp_volume := 0.0
    sum_volume := 0.0
    sum_sq_diff_volume := 0.0

tp = (high + low + close) / 3
sum_tp_volume := sum_tp_volume + (tp * volume)
sum_volume := sum_volume + volume
currentDailyVwap = sum_volume != 0 ? sum_tp_volume / sum_volume : dailyVwap

if not na(currentDailyVwap) and volume > 0
    sum_sq_diff_volume := sum_sq_diff_volume + (math.pow(tp - currentDailyVwap, 2) * volume)

stdDevVwap = sum_volume != 0 ? math.sqrt(sum_sq_diff_volume / sum_volume) : 0.0

// Inputs for band multipliers
stdDevMultiplierEntry = input.float(1.0, "Entry Band Multiplier", minval=0.1, step=0.1)
stdDevMultiplierExit = input.float(0.5, "Exit Band Multiplier (Target)", minval=0.1, step=0.1)
stopLossMultiplier = input.float(2.5, "Stop Loss Multiplier (relative to StdDev)", minval=0.1, step=0.1)

lowerBandEntry = currentDailyVwap - (stdDevVwap * stdDevMultiplierEntry)
upperBandEntry = currentDailyVwap + (stdDevVwap * stdDevMultiplierEntry)
lowerBandTarget = currentDailyVwap + (stdDevVwap * stdDevMultiplierExit)
upperBandTarget = currentDailyVwap - (stdDevVwap * stdDevMultiplierExit)

// Plot bands for visualization
plot(lowerBandEntry, "Lower Entry Band", color=color.green, style=plot.style_stepline)
plot(upperBandEntry, "Upper Entry Band", color=color.red, style=plot.style_stepline)

// Long Entry Condition
longCondition = close > lowerBandEntry and close[1] <= lowerBandEntry[1] and close > open
if (longCondition)
    strategy.entry("Long Reversion", strategy.long)

// Short Entry Condition
shortCondition = close < upperBandEntry and close[1] >= upperBandEntry[1] and close < open
if (shortCondition)
    strategy.entry("Short Reversion", strategy.short)

// Long Exit
longStopPrice = strategy.position_avg_price - (stdDevVwap * stopLossMultiplier)
strategy.exit("Long Reversion Exit", from_entry="Long Reversion", profit=upperBandTarget, stop=longStopPrice)

// Short Exit
shortStopPrice = strategy.position_avg_price + (stdDevVwap * stopLossMultiplier)
strategy.exit("Short Reversion Exit", from_entry="Short Reversion", profit=lowerBandTarget, stop=shortStopPrice)

2. VWAP Trend Confirmation

In a strong intraday trend, price will consistently stay on one side of the VWAP. VWAP itself will also be sloping in the direction of the trend.


//@version=5
strategy("VWAP Trend Following Strategy", overlay=true)

dailyVwap = ta.vwap(close, volume)
plot(dailyVwap, "Daily VWAP", color=color.purple, linewidth=2)

// Define bullish and bearish VWAP slopes for trend confirmation
vwapSlopePeriod = input.int(5, "VWAP Slope Lookback", minval=1)
isVwapUptrend = dailyVwap > dailyVwap[vwapSlopePeriod]
isVwapDowntrend = dailyVwap < dailyVwap[vwapSlopePeriod]

// Long Entry: Price crosses above VWAP, and VWAP is trending up
longCondition = ta.crossover(close, dailyVwap) and isVwapUptrend

// Short Entry: Price crosses below VWAP, and VWAP is trending down
shortCondition = ta.crossunder(close, dailyVwap) and isVwapDowntrend

if (longCondition)
    strategy.entry("Long Trend", strategy.long)

if (shortCondition)
    strategy.entry("Short Trend", strategy.short)

// Exit: Price crosses back over VWAP, indicating trend weakness
strategy.close("Long Trend", when=ta.crossunder(close, dailyVwap))
strategy.close("Short Trend", when=ta.crossover(close, dailyVwap))

3. VWAP Anchor Points / Breakouts

VWAP can act as a crucial anchor point for breakouts. A decisive break from VWAP, especially on higher volume, can signal the start of a strong directional move.


//@version=5
strategy("VWAP Breakout Strategy", overlay=true)

dailyVwap = ta.vwap(close, volume)
plot(dailyVwap, "Daily VWAP", color=color.purple, linewidth=2)

// Using VWAP Bands to define breakout zones
var float sum_tp_volume = 0.0
var float sum_volume = 0.0
var float sum_sq_diff_volume = 0.0

if ta.change(time("D"))
    sum_tp_volume := 0.0
    sum_volume := 0.0
    sum_sq_diff_volume := 0.0

tp = (high + low + close) / 3
sum_tp_volume := sum_tp_volume + (tp * volume)
sum_volume := sum_volume + volume
currentDailyVwap = sum_volume != 0 ? sum_tp_volume / sum_volume : dailyVwap

if not na(currentDailyVwap) and volume > 0
    sum_sq_diff_volume := sum_sq_diff_volume + (math.pow(tp - currentDailyVwap, 2) * volume)

stdDevVwap = sum_volume != 0 ? math.sqrt(sum_sq_diff_volume / sum_volume) : 0.0

stdDevMultiplierBreakout = input.float(1.5, "Breakout Band Multiplier", minval=0.1, step=0.1)
minVolumeMultiplier = input.float(1.5, "Min Volume Multiplier for Breakout", minval=1.0, step=0.1)

upperBandBreakout = currentDailyVwap + (stdDevVwap * stdDevMultiplierBreakout)
lowerBandBreakout = currentDailyVwap - (stdDevVwap * stdDevMultiplierBreakout)

plot(upperBandBreakout, "Upper Breakout Band", color=color.gray, style=plot.style_stepline)
plot(lowerBandBreakout, "Lower Breakout Band", color=color.gray, style=plot.style_stepline)

// Calculate average volume for confirmation
avgVolume = ta.sma(volume, 20)
isHighVolume = volume > avgVolume * minVolumeMultiplier

// Long Breakout: Price crosses above upper breakout band with high volume
longBreakoutCondition = close > upperBandBreakout and close[1] <= upperBandBreakout[1] and isHighVolume

// Short Breakout: Price crosses below lower breakout band with high volume
shortBreakoutCondition = close < lowerBandBreakout and close[1] >= lowerBandBreakout[1] and isHighVolume

if (longBreakoutCondition)
    strategy.entry("Long Breakout", strategy.long)

if (shortBreakoutCondition)
    strategy.entry("Short Breakout", strategy.short)

// Basic exit: Price crosses back over VWAP, or hits opposite band
strategy.close("Long Breakout", when=close < dailyVwap or close < lowerBandBreakout)
strategy.close("Short Breakout", when=close > dailyVwap or close > upperBandBreakout)

Optimizing Daily VWAP Performance

To get the most from Daily VWAP in Pine Script:

Fair Value & Institutional Flow: VWAP is considered the "true" average price for the day. Institutional traders often target closing positions near VWAP, making it a magnet for price.

Common Daily VWAP Pitfalls

Conclusion

The Daily Volume Weighted Average Price (VWAP) is an indispensable technical indicator in Pine Script for TradingView, offering unique insights into intraday market dynamics. By providing a volume-weighted average price for the current trading session, it serves as a critical benchmark for institutional traders, a dynamic support/resistance level, and a powerful confirmation tool for short-term trends. While its daily reset makes it exclusively an intraday indicator, mastering its application for mean reversion, trend confirmation, and identifying breakouts, ideally in conjunction with VWAP bands and other volume analysis, can significantly enhance your intraday trading strategies and provide a clearer understanding of the market's true fair value.