TradingView indicator comparisons

VWAP vs TWAP: time weighting, volume weighting and proxies

VWAP weights prices by volume; TWAP weights them by the time they represent. On complete, equally spaced samples, a sampled TWAP is their arithmetic mean. With the same four prices below, changing only the volume allocation moves VWAP from $103.60 to $101.20 while TWAP remains $103. A fair chart comparison fixes the source, timestamps, window and confirmation time. Neither plotted average is an order execution algorithm.

See the decision guide

Change volume while holding four prices fixed

Assume four consecutive, complete one-minute bars with closes of $100, $104, $102 and $106. Both averages use those closes and begin at minute 1. Volumes are hypothetical shares; prices and times are unchanged between cases A and B. These are arithmetic examples, not market observations or backtests.

  • TWAP = sum(price) / 4 = (100 + 104 + 102 + 106) / 4 = $103 in both cases.
  • VWAP = sum(price × volume) / sum(volume). A gives (10,000 + 72,800 + 10,200 + 10,600) / 1,000 = $103.60. B gives (70,000 + 10,400 + 10,200 + 10,600) / 1,000 = $101.20.
  • Both volume totals are 1,000 shares. Their allocation, rather than total activity alone, causes the $2.40 difference. Multiplying all volumes by the same positive factor leaves VWAP unchanged.
  • If every bar has 100 shares, VWAP is $103 too. Different volume weights can also happen to cancel, so equal outputs do not prove equal volumes.
MinuteCloseTWAP weightA: shares / VWAP weightB: shares / VWAP weight
1$10025%100 / 10%700 / 70%
2$10425%700 / 70%100 / 10%
3$10225%100 / 10%100 / 10%
4$10625%100 / 10%100 / 10%

Compare values available at the same close

For case A, accumulate both numerators and denominators from minute 1. The table shows the values available at each completed minute. The final four-minute average is unavailable at the earlier closes; using it there would introduce future information.

  • TradingView documents OHLC4 as the default TWAP source and HLC3 as the default VWAP source. Set both to Close before attributing a difference to volume weighting.
  • Match the exchange symbol, regular or extended session, chart interval, anchor and zero display offset. A daily reset and an arbitrary four-minute start describe different windows.
  • A value above or below either average describes a relationship to past samples. It does not identify institutional buying, predict a reversal or establish a profitable entry rule.
Completed minuteCumulative sharesSampled TWAPBar-based VWAP
1100$100.0000$100.0000
2800$102.0000$103.5000
3900$102.0000$103.3333
41,000$103.0000$103.6000

Time sampling can change the answer without a new trade

An equal-bar average represents equal time only when every included sample stands for the same duration. Under an explicitly assumed constant-price interval model, duration-weighted TWAP = sum(price × duration) / sum(duration). If the same four prices represent 1, 3, 1 and 1 minutes, the result is (100 + 312 + 102 + 106) / 6 = $103.3333, not the equal-observation mean of $103. The duration assignment is an assumption; four closes alone cannot reveal the path between them.

  • Resample case A into two two-minute bars using their closes: $104 and $106, with volumes 800 and 200. Equal-bar TWAP becomes $105 and close-based VWAP becomes (104 × 800 + 106 × 200) / 1,000 = $104.40. The clock window is unchanged, but the first and third close samples were discarded.
  • A transaction VWAP needs transaction prices and quantities. For trades of 9 shares at $100 and 1 share at $110, it is $101. Assigning all 10 shares to a bar close of $110 instead gives a $110 proxy. OHLC4 and HLC3 are also representative bar prices, not reconstructions of every transaction.
  • Range and tick bars have variable durations. Missing minutes, exchange closures and a short final bar require a stated coverage policy; equal weight per available bar does not repair missing time.

Keep missing volume separate from zero volume

Apply these changes to case A while keeping all four prices fixed unless the row says a bar is absent. The script uses a strict policy: valid observed prices can support TWAP, but any unknown or negative volume invalidates VWAP for the rest of the selected window. It never substitutes one weighting method for the other.

  • Dropping the absent $104 minute would give an available-observation mean of (100 + 102 + 106) / 3 = $102.6667. It is not the complete four-minute TWAP.
  • A zero-volume bar with a reported close is usable in the stated sampling model, but that close may be carried or stale. Inspect the feed before treating it as evidence of active trading.
  • If the first loaded bar is later than the chosen start, the script rejects price coverage. A later valid bar does not recover a missing earlier sample.
Input conditionTWAP proxyVWAP proxy / reason
Minute 2 volume is a known zero$103$102.6667: 30,800 / 300; minute 2 has zero volume weight
All four volumes are zero$103Unavailable: zero denominator
Minute 2 volume is missing$103Unavailable: the unknown weight could change the answer
Minute 2 price bar is absentIncomplete windowIncomplete window: the same price sample is missing
Volume measures tick activityUnaffected if prices matchTick-activity-weighted proxy; do not label the units as shares

Pine v6: one window, one source, one confirmation rule

Paste this indicator into Pine Editor and add it to a standard one-minute chart. Select a loaded bar opening as Window start and choose a window within a continuous trading period. The default is four minutes; the end is exclusive. Both calculations use close and update only when the chart bar is confirmed. The script plots cumulative values within the window, not a rolling average or an exchange-session VWAP.

  • Inspect the final selected bar in the Data Window. Full window complete must be 1, observed minutes must equal Window minutes, and volume coverage valid must be 1 before accepting the final VWAP. Its denominator must also be positive.
  • Until the last minute closes, the plotted values cover only elapsed samples. No value is plotted on an open bar or beyond the selected window. If the trailing minute is absent entirely, no final point can appear and Full window complete remains 0 at the last observed point.
  • A missing interior minute, misaligned start, shortened bar or missing close makes price coverage invalid. Both lines then become unavailable. Missing volume leaves TWAP available but makes VWAP unavailable; Known volume sum is only a partial sum in that case.
  • The chart restriction avoids treating equal bars as equal time on synthetic or non-time charts. The script makes no higher-timeframe requests, imputes no prices and places no orders. A syntax pass does not verify the feed or establish live trading performance.
Matched close samples with strict minute coverage and explicit volume validityPine Script v6
//@version=6
indicator("VWAP vs TWAP: matched window", overlay = true)
int startTime = input.time(timestamp("01 Oct 2026 13:30 +0000"), "Window start", confirm = true)
int windowMinutes = input.int(4, "Window minutes", minval = 1, maxval = 1440)
if not chart.is_standard or not timeframe.isminutes or timeframe.multiplier != 1
    runtime.error("Use a standard one-minute chart.")
int endTime = startTime + windowMinutes * 60000
bool inWindow = time >= startTime and time < endTime
var float priceSum = 0.0
var float priceVolumeSum = 0.0
var float volumeSum = 0.0
var int sampleCount = 0
var bool priceCoverageValid = true
var bool volumeCoverageValid = true
if inWindow and barstate.isconfirmed
    bool fullMinute = time_close - time == 60000
    bool expectedOpen = time == startTime + sampleCount * 60000
    priceCoverageValid := priceCoverageValid and fullMinute and expectedOpen and not na(close)
    volumeCoverageValid := volumeCoverageValid and not na(volume) and volume >= 0
    sampleCount += 1
    if not na(close)
        priceSum += close
        if not na(volume) and volume >= 0
            priceVolumeSum += close * volume
            volumeSum += volume
bool visible = inWindow and barstate.isconfirmed
float twapProxy = priceCoverageValid and sampleCount > 0 ? priceSum / sampleCount : na
float vwapProxy = priceCoverageValid and volumeCoverageValid and volumeSum > 0 ? priceVolumeSum / volumeSum : na
plot(visible ? twapProxy : na, "TWAP close-sample proxy", color.blue, 2, plot.style_linebr)
plot(visible ? vwapProxy : na, "VWAP close-volume proxy", color.orange, 2, plot.style_linebr)
plot(visible ? sampleCount : na, "Observed minutes", display = display.data_window)
plot(visible ? volumeSum : na, "Known volume sum", display = display.data_window)
plot(visible ? (priceCoverageValid ? 1 : 0) : na, "Price coverage valid: 1=yes", display = display.data_window)
plot(visible ? (volumeCoverageValid ? 1 : 0) : na, "Volume coverage valid: 1=yes", display = display.data_window)
plot(visible ? (priceCoverageValid and sampleCount == windowMinutes ? 1 : 0) : na, "Full window complete: 1=yes", display = display.data_window)

Separate a chart benchmark from an execution schedule

A chart average summarizes observations. An execution algorithm schedules and manages child orders with a broker. As a simplified illustration, allocating a 1,000-share order equally across four time slots gives 250 shares per slot. Allocating it by case A volume weights gives 100, 700, 100 and 100 shares. Actual future volume weights are not known at the start, and these allocations are not fill guarantees or specifications of a particular broker algorithm.

  • Interactive Brokers documents separate TWAP and VWAP execution algorithms with start/end settings and execution constraints. Its documentation warns that orders can remain partly unfilled; a target benchmark is not a promised fill price.
  • Actual average fill price is sum(fill price × filled quantity) / total filled quantity. Compare it with a benchmark over the same horizon and report unfilled quantity, spread, fees and slippage separately.
  • Pineify can help draft and revise the comparison script. This workflow does not route orders or execute TWAP slices. Keep any broker execution integration and permissions separate from the indicator.

Choose the weighting rule before testing a trading rule

Use time weights when the research question concerns prices across equal intervals. Use volume weights when the question concerns prices weighted by the reported activity, after verifying what that volume represents. Neither choice establishes better entries. For a strategy comparison, change only the selected average first and hold the window, price source, confirmation rule, fill timing and costs fixed.

  • Give the Pine Script AI Coding Agent this indicator and state the intended entry/exit condition. Ask it to retain the same coverage checks and expose the selected average as an input.
  • Request a syntax check, then compare the first differing condition on completed bars. Test zero volume, missing volume, a gap and a window beyond loaded history before interpreting a backtest.
Where Pineify fits

Pine Script AI Coding Agent

Draft or revise a Pine Script comparison with shared inputs and explicit missing-data rules. Request a syntax check and inspect its behavior in TradingView.

Build a matched-average script

Frequently asked questions

Educational information, not investment advice. Numerical examples are hypothetical calculations, not historical performance or executable prices. Chart proxies and generated scripts do not guarantee fills or returns.

Sources and verification

Published by Pineify. Pineify is an independent product and is not affiliated with TradingView. Sources support the technical explanations; examples do not establish trading performance.