Anchored VWAP
Volume-weighted average price counted from a chosen start time, with optional volume-weighted standard deviation bands.
- AVWAP
- Built into Spectral
- Updates every tick
- Uses volume
- anchored vwap
- vwap
- volume weighted
- anchor
- standard deviation bands
MIT-0: free to use, change and share, no attribution needed. What you build from it is yours.
Already in Spectral: add it from the Indicators toolbox. The file here is the same indicator written as a custom indicator, to change or learn from. Installed, it appears next to the built-in one, marked Custom.

Overview
Anchored VWAP is the volume-weighted average price counted from a bar you choose, instead of from the start of the session. Every price from the anchor onward is weighted by its volume, so the line shows the average price paid by everyone who traded since that moment.
Traders anchor it to events that matter: a swing high or low, an earnings release, a gap, a breakout or the start of a trend. Optional bands at a chosen number of volume-weighted standard deviations show how far price has stretched from that average.
How to read it
The line is the average cost of all volume since the anchor. Price above it means that, on average, participants who entered at the anchor are in profit; below it, in loss. Price often returns to an anchored VWAP and reacts there, acting as dynamic support after an upward anchor and as resistance after a downward one.
The bands mark stretched conditions around that average, narrow at first and wider as more volume accumulates. A line anchored too close to the present is noisy because few bars have contributed yet. It tells you the average price, not why price moved.
Settings and limitations
Anchor time sets the start as a New York date and time; the bar that contains that moment is the first bar of the calculation. Values before the anchor are empty. An anchor earlier than the first loaded bar starts at the first loaded bar (scroll back to load more history if you want the true start). An anchor after the last bar draws nothing yet. When Anchor time is not set, the VWAP starts at the first bar of the latest New York trading date on the chart, which gives a VWAP for today. It counts all bars of that date, so on an extended-hours chart it includes pre-market and starts at 04:00; set an Anchor time at 09:30 to start at the open.
Source is the weighted price (hlc3 by default). Band 1, 2 and 3 switch each pair on or off (only band 1 by default) and the multipliers set their distance in standard deviations (1, 2 and 3). Shaded zones fills between each enabled pair.
Notes
The calculation is the standard anchored VWAP: the cumulative sum of price times volume divided by the cumulative volume from the anchor bar, with bands at multiples of the volume-weighted standard deviation, as in TradingView's Anchored VWAP. TradingView lets you click the anchor on the chart; here it is a setting. Bars with no volume do not move the line. The line has no value until the first bar with volume at or after the anchor. The first bar after an anchor is exactly the source price, so the bands start at zero width.
Settings
Each setting appears in the indicator's settings panel in Spectral, next to a color setting for every output.
| Setting | Type | Default | Range or options | What it does |
|---|---|---|---|---|
| Anchor time | Date and time | Not set | — | The moment the VWAP starts, as a New York date and time. Not set: the VWAP starts at the first bar of the latest trading date on the chart. |
| Source | Price source | hlc3 | open, high, low, close, hlc3 | Price weighted by volume. hlc3 is the average of high, low and close. |
| Band 1 | On / off | On | — | Draw the first pair of bands. |
| Band 1 multiplier | Number | 1 | 0.1 – 10, step 0.1 | Distance of the first bands from VWAP, in standard deviations. |
| Band 2 | On / off | Off | — | Draw the second pair of bands. |
| Band 2 multiplier | Number | 2 | 0.1 – 10, step 0.1 | Distance of the second bands from VWAP, in standard deviations. |
| Band 3 | On / off | Off | — | Draw the third pair of bands. |
| Band 3 multiplier | Number | 3 | 0.1 – 10, step 0.1 | Distance of the third bands from VWAP, in standard deviations. |
| Shaded zones | On / off | On | — | Fill the area between each pair of enabled bands with a light color. |
Presets
Each preset is its own entry in the Indicators toolbox, with these settings changed.
| Toolbox entry | Short name | Settings |
|---|---|---|
| Anchored VWAP (no bands) | AVWAP | Band 1: falseBand 2: falseBand 3: false |
| Anchored VWAP (bands 1, 2, 3) | AVWAP 1-2-3 | Band 1: trueBand 2: trueBand 3: true |
What it draws
Lines
- AVWAPsolid · 1.5 px · primary
#A895D0 - Upper band 1solid · 1 px
#A895D0 - Lower band 1solid · 1 px
#A895D0 - Upper band 2dashed · 1 px
#A895D0 - Lower band 2dashed · 1 px
#A895D0 - Upper band 3dotted · 1 px
#A895D0 - Lower band 3dotted · 1 px
#A895D0
Zones
- Zone 1filled at 7% opacity
#A895D0 - Zone 2filled at 5% opacity
#A895D0 - Zone 3filled at 3% opacity
#A895D0
Source
Save it as anchored-vwap.js and add it with Indicators → Custom indicators → Add file…. The format is explained in the custom indicators guide.
// Copyright (c) 2026 Spectral
// SPDX-License-Identifier: MIT-0
// Free to use, copy, modify and share: https://spectral.trade/docs/custom-indicators/LICENSE.txt
/** @type {import('./spectral-indicator').IndicatorV2} */
export default {
schemaVersion: 2,
id: 'anchored-vwap',
name: 'Anchored VWAP',
shortName: 'AVWAP',
version: '1.0.0',
author: 'Spectral',
description: 'Volume-weighted average price counted from a chosen start time, with optional volume-weighted standard deviation bands.',
pane: 'price',
live: { lookback: 0 },
usesVolume: true,
inputs: {
anchorTime: { type: 'time', label: 'Anchor time', default: 0, description: 'The moment the VWAP starts, as a New York date and time. Not set: the VWAP starts at the first bar of the latest trading date on the chart.' },
source: { type: 'source', label: 'Source', default: 'hlc3', description: 'Price weighted by volume. hlc3 is the average of high, low and close.' },
showBand1: { type: 'boolean', label: 'Band 1', default: true, description: 'Draw the first pair of bands.' },
mult1: { type: 'number', label: 'Band 1 multiplier', default: 1, min: 0.1, max: 10, step: 0.1, description: 'Distance of the first bands from VWAP, in standard deviations.' },
showBand2: { type: 'boolean', label: 'Band 2', default: false, description: 'Draw the second pair of bands.' },
mult2: { type: 'number', label: 'Band 2 multiplier', default: 2, min: 0.1, max: 10, step: 0.1, description: 'Distance of the second bands from VWAP, in standard deviations.' },
showBand3: { type: 'boolean', label: 'Band 3', default: false, description: 'Draw the third pair of bands.' },
mult3: { type: 'number', label: 'Band 3 multiplier', default: 3, min: 0.1, max: 10, step: 0.1, description: 'Distance of the third bands from VWAP, in standard deviations.' },
showZones: { type: 'boolean', label: 'Shaded zones', default: true, description: 'Fill the area between each pair of enabled bands with a light color.' },
},
plots: {
vwap: { label: 'AVWAP', color: '#A895D0', lineWidth: 1.5, primary: true },
upper1: { label: 'Upper band 1', color: '#A895D0' },
lower1: { label: 'Lower band 1', color: '#A895D0' },
upper2: { label: 'Upper band 2', color: '#A895D0', lineStyle: 'dashed' },
lower2: { label: 'Lower band 2', color: '#A895D0', lineStyle: 'dashed' },
upper3: { label: 'Upper band 3', color: '#A895D0', lineStyle: 'dotted' },
lower3: { label: 'Lower band 3', color: '#A895D0', lineStyle: 'dotted' },
},
zones: {
zone1: { label: 'Zone 1', color: '#A895D0', opacity: 0.07 },
zone2: { label: 'Zone 2', color: '#A895D0', opacity: 0.05 },
zone3: { label: 'Zone 3', color: '#A895D0', opacity: 0.03 },
},
presets: [
{ id: 'vwap-only', name: 'Anchored VWAP (no bands)', shortName: 'AVWAP', inputs: { showBand1: false, showBand2: false, showBand3: false } },
{ id: 'bands-1-2-3', name: 'Anchored VWAP (bands 1, 2, 3)', shortName: 'AVWAP 1-2-3', inputs: { showBand1: true, showBand2: true, showBand3: true } },
],
docs: {
overview: 'Anchored VWAP is the volume-weighted average price counted from a bar you choose, instead of from the start of the session. Every price from the anchor onward is weighted by its volume, so the line shows the average price paid by everyone who traded since that moment.\n\nTraders anchor it to events that matter: a swing high or low, an earnings release, a gap, a breakout or the start of a trend. Optional bands at a chosen number of volume-weighted standard deviations show how far price has stretched from that average.',
howToRead: 'The line is the average cost of all volume since the anchor. Price above it means that, on average, participants who entered at the anchor are in profit; below it, in loss. Price often returns to an anchored VWAP and reacts there, acting as dynamic support after an upward anchor and as resistance after a downward one.\n\nThe bands mark stretched conditions around that average, narrow at first and wider as more volume accumulates. A line anchored too close to the present is noisy because few bars have contributed yet. It tells you the average price, not why price moved.',
settings: 'Anchor time sets the start as a New York date and time; the bar that contains that moment is the first bar of the calculation. Values before the anchor are empty. An anchor earlier than the first loaded bar starts at the first loaded bar (scroll back to load more history if you want the true start). An anchor after the last bar draws nothing yet. When Anchor time is not set, the VWAP starts at the first bar of the latest New York trading date on the chart, which gives a VWAP for today. It counts all bars of that date, so on an extended-hours chart it includes pre-market and starts at 04:00; set an Anchor time at 09:30 to start at the open.\n\nSource is the weighted price (hlc3 by default). Band 1, 2 and 3 switch each pair on or off (only band 1 by default) and the multipliers set their distance in standard deviations (1, 2 and 3). Shaded zones fills between each enabled pair.',
notes: 'The calculation is the standard anchored VWAP: the cumulative sum of price times volume divided by the cumulative volume from the anchor bar, with bands at multiples of the volume-weighted standard deviation, as in TradingView\'s Anchored VWAP. TradingView lets you click the anchor on the chart; here it is a setting. Bars with no volume do not move the line. The line has no value until the first bar with volume at or after the anchor. The first bar after an anchor is exactly the source price, so the bands start at zero width.',
},
calculate(ctx) {
const { bars, inputs, ta, time, barSize } = ctx;
const count = bars.length;
const price = ta.source(bars, inputs.source);
const anchor = inputs.anchorTime;
const seconds = barSeconds(barSize);
const items = bars.map((bar, index) => ({ bar, price: price[index] }));
// The weight, mean and spread since the start carry from bar to bar through ta.scan. With an anchor, a bar that
// opens at or before it and spans it starts the sum again, any other bar at or before it clears the sum, and bars
// after it add to it. Without an anchor, every New York date starts its own sum and only the latest date is drawn.
const zero = { weight: 0, mean: 0, spread: 0, date: '' };
const states = ta.scan(items, zero, (state, item) => {
let { weight, mean, spread } = state;
let date = '';
if (anchor > 0) {
if (item.bar.time <= anchor) {
if (anchor >= item.bar.time + seconds) return zero;
({ weight, mean, spread } = zero);
}
} else {
date = time.ny(item.bar).dateKey;
if (date !== state.date) ({ weight, mean, spread } = zero);
}
const volume = Number(item.bar.volume);
if (Number.isFinite(volume) && volume > 0) {
// Weighted incremental mean and variance: stable and identical to sum(v*p)/sum(v) and sum(v*p*p)/sum(v) - vwap*vwap.
weight += volume;
const delta = item.price - mean;
mean += (volume / weight) * delta;
spread += volume * delta * (item.price - mean);
}
return { weight, mean, spread, date };
});
// A bar at or before the anchor contains it only when the next bar opens after the anchor (or there is no next bar
// yet); one whose next bar opens at or before it is not drawn, and that next bar starts the sum again.
const contains = (index) => anchor <= 0 || bars[index].time > anchor || index === count - 1 || bars[index + 1].time > anchor;
// Not set: only the chart's latest New York trading date is drawn.
const latest = anchor > 0 || count === 0 ? '' : time.ny(bars[count - 1]).dateKey;
const drawn = (state, index) => state.weight > 0 && state.date === latest && contains(index);
const vwap = states.map((state, index) => (drawn(state, index) ? state.mean : null));
const deviation = states.map((state, index) => (drawn(state, index) ? Math.sqrt(Math.max(0, state.spread / state.weight)) : null));
const plots = { vwap };
const zones = {};
const shown = [inputs.showBand1, inputs.showBand2, inputs.showBand3];
const multipliers = [inputs.mult1, inputs.mult2, inputs.mult3];
for (let band = 0; band < 3; band += 1) {
const upper = shown[band] ? offsetSeries(vwap, deviation, multipliers[band]) : new Array(count).fill(null);
const lower = shown[band] ? offsetSeries(vwap, deviation, -multipliers[band]) : new Array(count).fill(null);
plots['upper' + (band + 1)] = upper;
plots['lower' + (band + 1)] = lower;
if (shown[band] && inputs.showZones) zones['zone' + (band + 1)] = { upper, lower };
}
return { plots, zones };
},
};
function offsetSeries(center, deviation, multiplier) {
return center.map((value, index) => (value === null || deviation[index] === null ? null : value + multiplier * deviation[index]));
}
/** Seconds covered by one bar of a Spectral bar size such as '5 mins', '1 hour' or '1 day'. */
function barSeconds(barSize) {
const parts = String(barSize).split(' ');
const amount = Number(parts[0]);
const unit = parts.length > 1 ? parts[1] : 'min';
let seconds = 60;
if (unit.startsWith('sec')) seconds = 1;
else if (unit.startsWith('hour')) seconds = 3600;
else if (unit.startsWith('day')) seconds = 86400;
else if (unit.startsWith('week')) seconds = 604800;
else if (unit.startsWith('month')) seconds = 2678400;
return (Number.isFinite(amount) && amount > 0 ? amount : 1) * seconds;
}Adapt it with an LLM
Paste this into your assistant and replace the second-to-last line with the change you want.
Start from this Spectral custom indicator: https://spectral.trade/indicators/anchored-vwap.js Format reference: https://spectral.trade/docs/custom-indicators.llm.md Keep the file format and every rule of the reference; give the result a new id, name, shortName and version, and update docs and input descriptions to match. Keep its live updates exact and fast (section "Fast live updates" of the reference): carry values from bar to bar only through ctx.ta, and raise live.lookback if the change reads further back; Spectral rejects a file whose live updates differ from a full recalculation or are too slow. Change I want: <describe the change> Answer with the complete file in one code block, ready to save as <id>.js.


