anchoredVWAP

Anchored VWAP pins the Volume-Weighted Average Price to a bar you choose and carries it forward. Use it to see โ€œfair valueโ€ starting from key moments (breakouts, earnings, session open) and optionally add deviation bands to gauge stretch/mean-reversion.

Syntax (one line)

anchoredVWAP(initialPoint, styles?)

Parameters

initialPoint (PricedData) ยท Bar (time & price) where the VWAP anchor starts, e.g. newPoint(time(80), closeC(80)). styles (AnchoredvwapLineToolOverrides) ยท Full visual + calculation controls for line, bands, and background.

  • areaBackground (object) ยท Background fill under VWAP and bands. ยท backgroundColor (RGBAColor | BaseColors) ยท Color for the filled area. ยท fillBackground (boolean) ยท Turn background fill on/off. ยท transparency (number) ยท 0โ€“100 background opacity.

  • filledAreasStyle (object) ยท Per-zone background controls. ยท Background_1.color (RGBAColor | BaseColors) ยท Zone color. ยท Background_1.transparency (number) ยท 0โ€“100 opacity. ยท Background_1.visible (boolean) ยท Show/hide this zone.

  • precision (string) ยท Number formatting for labels/values.

  • inputs (AnchoredvwapInputs) ยท VWAP calculation settings. ยท Bands Calculation Mode (enum) ยท Standard or Percent for band math. ยท bands_multiplier (number) ยท Multiplier for band 1 (stdev or %). ยท bands_multiplier_2 (number) ยท Multiplier for band 2. ยท bands_multiplier_3 (number) ยท Multiplier for band 3. ยท calculate_stDev (boolean) ยท Enable band 1 using stdev. ยท calculate_stDev_2 (boolean) ยท Enable band 2 using stdev. ยท calculate_stDev_3 (boolean) ยท Enable band 3 using stdev. ยท source (VWAPSource) ยท Price source (close, open, high, low, hl2, hlc3, ohlc4). ยท start_time (number) ยท Anchor timestamp (used internally from initialPoint).

  • styles (object) ยท Line styles for VWAP and each band. ยท VWAP (AnchoredvwapBands) ยท Main VWAP line style. ยท UpperBand (AnchoredvwapBands) ยท Upper band 1 style. ยท UpperBand_2 (AnchoredvwapBands) ยท Upper band 2 style. ยท UpperBand_3 (AnchoredvwapBands) ยท Upper band 3 style. ยท LowerBand (AnchoredvwapBands) ยท Lower band 1 style. ยท LowerBand_2 (AnchoredvwapBands) ยท Lower band 2 style. ยท LowerBand_3 (AnchoredvwapBands) ยท Lower band 3 style.

  • AnchoredvwapBands (object) ยท Shared line options for the above. ยท color (RGBAColor | BaseColors) ยท Line color. ยท display (number) ยท Display mode (implementation specific). ยท linestyle (number) ยท 0=solid, 1=dotted, 2=dashedโ€ฆ ยท linewidth (number) ยท Line thickness. ยท plottype (number) ยท Plot type (implementation specific). ยท trackPrice (boolean) ยท Show live price marker on the line. ยท transparency (number) ยท Line transparency 0โ€“100.

Return Value

(string) ยท The drawing ID of the created Anchored VWAP.

Example

What this does: Every 40 candles we anchor VWAP at a past pivot, show one set of deviation bands (ยฑ1.0), and softly fill the area between them.

//@version=1
init = () => {
  indicator({ onMainPanel: true, format: 'inherit' });
};

onTick = () => {
  // Draw occasionally to avoid clutter
  if (index % 40 === 0) {
    // 1) Choose an anchor bar (meaningful pivot/event)
    const anchor = newPoint(time(80), closeC(80));

    // 2) Full style following AnchoredvwapLineToolOverrides
    const style = {
      // Background under the VWAP/bands
      areaBackground: {
        backgroundColor: color.rgba(255, 165, 0, 0.12),
        fillBackground: true,
        transparency: 85
      },

      // Optional per-zone background (example using Background_1)
      filledAreasStyle: {
        Background_1: {
          color: color.rgba(255, 165, 0, 0.18),
          transparency: 82,
          visible: true
        }
      },

      // Label/number precision
      precision: 'auto',

      // Band calculations and source
      inputs: {
        'Bands Calculation Mode': 'Standard', // or 'Percent'
        bands_multiplier: 1.0,       // ยฑ1.0 band
        bands_multiplier_2: 0,       // disable others by setting 0 + calculate false
        bands_multiplier_3: 0,
        calculate_stDev: true,
        calculate_stDev_2: false,
        calculate_stDev_3: false,
        source: 'hlc3',              // typical VWAP source
        start_time: undefined        // derived from anchor; no need to set manually
      },

      // Line styles for VWAP and bands
      styles: {
        VWAP:       { color: color.orange, linestyle: 2, linewidth: 2, plottype: 0, trackPrice: true,  transparency: 0 },
        UpperBand:  { color: color.yellow, linestyle: 0, linewidth: 1, plottype: 0, trackPrice: false, transparency: 10 },
        LowerBand:  { color: color.yellow, linestyle: 0, linewidth: 1, plottype: 0, trackPrice: false, transparency: 10 },

        // Disabled bands (kept for clarity)
        UpperBand_2:{ color: color.gray,   linestyle: 1, linewidth: 1, plottype: 0, trackPrice: false, transparency: 80 },
        LowerBand_2:{ color: color.gray,   linestyle: 1, linewidth: 1, plottype: 0, trackPrice: false, transparency: 80 },
        UpperBand_3:{ color: color.gray,   linestyle: 1, linewidth: 1, plottype: 0, trackPrice: false, transparency: 80 },
        LowerBand_3:{ color: color.gray,   linestyle: 1, linewidth: 1, plottype: 0, trackPrice: false, transparency: 80 }
      }
    };

    // 3) Build anchored VWAP with deviation bands
    anchoredVWAP(anchor, style);
  }
};

Tips

  • Anchor at key events (breakout candle, session open, large volume bar) to see fair-value drift from that point.

  • Switch Bands Calculation Mode to Percent if you prefer percent-width bands rather than standard deviations.

  • Use trackPrice: true on VWAP so you always see the current value marker.

Warning

  • Donโ€™t over-enable bands (calculate_stDev_*) without reason โ€” too many lines + fills can clutter and slow the chart.

  • If you pass malformed anchors (missing time or price), nothing will draw. Always use newPoint(time(offset), price).

Good Practice

  • Keep a few presets (e.g., event VWAP: orange, session VWAP: blue) so you can compare contexts at a glance.

  • For mean-reversion testing, start with ยฑ1.0 stdev only; add ยฑ2/ยฑ3 stdev bands later if they add real value.

Last updated