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