VWAP (Volume Weighted Average Price)
VWAP calculates the average price weighted by volume across the entire session. It is widely used by institutional traders as a benchmark for trade execution quality.
Declaration
function init(ctx) { ctx.indicator('vwap', 'VWAP', {}); }
Options
VWAP requires no configuration. It uses high, low, close, and volume data automatically.
Output
Returns a single number[] series (price level).
Accessing Values
function onBar(ctx, i) { const vwap = ctx.ind.vwap[i]; const close = ctx.series.close[i]; // Price above VWAP = bullish bias // Price below VWAP = bearish bias }
Use Cases
VWAP Trend Filter
function onBar(ctx, i) { const close = ctx.series.close[i]; const vwap = ctx.ind.vwap[i]; // Only take long positions when price is above VWAP if (close > vwap && q.crossOver(ctx.ind.fast, ctx.ind.slow, i)) { ctx.order.market('ASSET', 1, { signal: 'buy', reason: 'above_vwap' }); } }
VWAP Bounce
function onBar(ctx, i) { const close = ctx.series.close[i]; const low = ctx.series.low[i]; const vwap = ctx.ind.vwap[i]; // Price touched VWAP and bounced if (low <= vwap && close > vwap) { ctx.order.market('ASSET', 1, { signal: 'buy', reason: 'vwap_bounce' }); } }
Calculation
$$VWAP = \frac{\sum (TP \times Volume)}{\sum Volume}$$
Where $TP = \frac{High + Low + Close}{3}$ (Typical Price), cumulative from session start.
Related
indicatorvwapvolumepriceinstitutionalqsl