Indicator · Pine Script v6 · On the chart

Dynamic Anchored VWAP

by ezPappi

Dynamic Anchored VWAP calculates a volume-weighted average price starting from a selected dynamic or manual anchor point, such as the chart start, daily start, weekly start, monthly start, or a specific timestamp.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code150
Settings10inputs
LicenceGPL-3.0
Last update1 year ago23 Jun 2025

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

150 lines of Pine Script v6 from dynamic_anchored_vwap.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

dynamic_anchored_vwap.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Based on script of © LonesomeTheBlue
// Trend Lines for RSI, CCI, Momentum, OBV and MACD
// By ezPappi
//@version=6
indicator("Dynamic Anchored VWAP", shorttitle="DAVWAP", overlay=true)

// Automatic anchor time options
anchor_type = input.string("Chart Start", title="Anchor Type", 
                          options=["Chart Start", "Daily Start", "Weekly Start", "Monthly Start", "Manual"])
manual_anchor = input.time(timestamp("2017-12-18 00:00"), title="Manual Anchor Time")

// Get the first bar time of the chart
var first_bar_time = time

// Function to get automatic anchor time
get_anchor_time() =>
    switch anchor_type
        "Chart Start" => 
            // Use the first bar of the chart
            first_bar_time
        "Daily Start" => 
            // Start of current day
            timestamp(year(time), month(time), dayofmonth(time), 0, 0)
        "Weekly Start" => 
            // Start of current week (Monday)
            week_start = time - (dayofweek(time) - 2) * 24 * 60 * 60 * 1000
            timestamp(year(week_start), month(week_start), dayofmonth(week_start), 0, 0)
        "Monthly Start" => 
            // Start of current month
            timestamp(year(time), month(time), 1, 0, 0)
        => manual_anchor

anchor_time = get_anchor_time()

// Display options
show_labels = input.bool(true, title="Show Labels")
show_bands = input.bool(true, title="Show Standard Deviation Bands")

// Standard deviation multipliers
sd1_mult = input.float(1.0, title="1st SD Multiplier", minval=0.1, step=0.1)
sd2_mult = input.float(2.0, title="2nd SD Multiplier", minval=0.1, step=0.1)
sd3_mult = input.float(3.0, title="3rd SD Multiplier", minval=0.1, step=0.1)

// Colors
vwap_color = input.color(color.rgb(155, 139, 0), title="VWAP Color")
upper_color = input.color(color.lime, title="Upper Bands Color")
lower_color = input.color(color.red, title="Lower Bands Color")

// Check if we're at or after anchor time
is_anchor_start = time >= anchor_time and time[1] < anchor_time
is_after_anchor = time >= anchor_time

// Initialize variables
var float sum_pv = 0.0
var float sum_v = 0.0
var int bar_count = 0
var float sum_price = 0.0
var float sum_squared_diff = 0.0

// Calculate VWAP and standard deviation
if is_anchor_start
    // Reset at anchor start
    sum_pv := hlc3 * volume
    sum_v := volume
    bar_count := 1
    sum_price := hlc3
    sum_squared_diff := 0.0
else if is_after_anchor
    // Accumulate values
    sum_pv += hlc3 * volume
    sum_v += volume
    bar_count += 1
    sum_price += hlc3

// Calculate VWAP
vwap = is_after_anchor ? sum_pv / sum_v : na

// Calculate standard deviation
mean_price = is_after_anchor ? sum_price / bar_count : na

// Initialize band variables
var float sd1_upper = na
var float sd1_lower = na
var float sd2_upper = na
var float sd2_lower = na
var float sd3_upper = na
var float sd3_lower = na

if is_after_anchor and bar_count > 1
    sum_squared_diff += math.pow(hlc3 - mean_price, 2)
    variance = sum_squared_diff / (bar_count - 1)
    std_dev = math.sqrt(variance)
    
    // Calculate bands
    sd1_upper := vwap + (std_dev * sd1_mult)
    sd1_lower := vwap - (std_dev * sd1_mult)
    sd2_upper := vwap + (std_dev * sd2_mult)
    sd2_lower := vwap - (std_dev * sd2_mult)
    sd3_upper := vwap + (std_dev * sd3_mult)
    sd3_lower := vwap - (std_dev * sd3_mult)

// Plot bands (in global scope)
plot(show_bands and is_after_anchor ? sd1_upper : na, color=upper_color, linewidth=1, title="1st SD Upper")
plot(show_bands and is_after_anchor ? sd1_lower : na, color=lower_color, linewidth=1, title="1st SD Lower")
plot(show_bands and is_after_anchor ? sd2_upper : na, color=upper_color, linewidth=1, title="2nd SD Upper")
plot(show_bands and is_after_anchor ? sd2_lower : na, color=lower_color, linewidth=1, title="2nd SD Lower")
plot(show_bands and is_after_anchor ? sd3_upper : na, color=upper_color, linewidth=1, title="3rd SD Upper")
plot(show_bands and is_after_anchor ? sd3_lower : na, color=lower_color, linewidth=1, title="3rd SD Lower")

// Plot VWAP
plot(vwap, color=vwap_color, linewidth=2, title="Anchored VWAP")

// Add labels with price values
if show_labels and is_after_anchor and barstate.islast
    // VWAP label with price
    label.new(bar_index, vwap, "AVWAP: " + str.tostring(vwap, "#.##"), 
              color=vwap_color, 
              textcolor=color.white, 
              style=label.style_label_left,
              size=size.small)
    
    // Standard deviation band labels with prices
    if show_bands and not na(sd1_upper)
        label.new(bar_index, sd1_upper, "+" + str.tostring(sd1_mult) + "σ: " + str.tostring(sd1_upper, "#.##"), 
                  color=upper_color, 
                  textcolor=color.white, 
                  style=label.style_label_left,
                  size=size.small)
        
        label.new(bar_index, sd1_lower, "-" + str.tostring(sd1_mult) + "σ: " + str.tostring(sd1_lower, "#.##"), 
                  color=lower_color, 
                  textcolor=color.white, 
                  style=label.style_label_left,
                  size=size.small)
        
        label.new(bar_index, sd2_upper, "+" + str.tostring(sd2_mult) + "σ: " + str.tostring(sd2_upper, "#.##"), 
                  color=upper_color, 
                  textcolor=color.white, 
                  style=label.style_label_left,
                  size=size.small)
        
        label.new(bar_index, sd2_lower, "-" + str.tostring(sd2_mult) + "σ: " + str.tostring(sd2_lower, "#.##"), 
                  color=lower_color, 
                  textcolor=color.white, 
                  style=label.style_label_left,
                  size=size.small)

// Background highlight for anchor bar
bgcolor(is_anchor_start ? color.new(color.blue, 90) : na, title="Anchor Start")

Overview

Dynamic Anchored VWAP calculates and plots the anchored VWAP alongside three optional standard deviation bands directly on the main price chart. Users can select the anchor mode, customize multiplier steps for standard deviation bands, and adjust visual color preferences for all overlay lines.

Details

Published by

ezPappi on GitHub

Draws

On the price chart

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Anchor TypestringChart Startanchor_type
Manual Anchor Timetimetimestamp("2017-12-18 00:00")manual_anchor
Show Labelsbooltrueshow_labels
Show Standard Deviation Bandsbooltrueshow_bands
1st SD Multiplierfloat1.0sd1_mult
2nd SD Multiplierfloat2.0sd2_mult
3rd SD Multiplierfloat3.0sd3_mult
VWAP Colorcolorcolor.rgb(155, 139, 0)vwap_color
Upper Bands Colorcolorcolor.limeupper_color
Lower Bands Colorcolorcolor.redlower_color
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Snag - VWAP

by dearvn
257 stars

This indicator plots a custom Anchored Volume-Weighted Average Price (VWAP) directly on the price chart along with optional standard deviation bands. Users can anchor the VWAP to standard time periods like sessions, weeks, or months, or to corporate events suc

Indicator v5 Moving averagesVolatility & bands Repaints
Updated 7 weeks ago · None stated GitHub repository of Snag - VWAP

VWAP - Basic

by TradersPost
228 stars

VWAP - Basic plots an anchored Volume Weighted Average Price directly on the main price chart alongside two standard deviation bands. It calculates typical price weighted by volume, resetting the cumulative calculations at user-selected session, weekly, or mon

Indicator v6 VolumeSupport & resistance
Updated 3 months ago · None stated GitHub repository of VWAP - Basic

D/W/M VWAPs

by cryptorife
75 stars

This indicator plots daily, weekly, and monthly volume-weighted average prices on the price chart, using a selectable source that defaults to hlc3. For each enabled period it also draws two standard-deviation bands around the VWAP, with multipliers defaulting

Indicator v4 VolumeVolatility & bands
Updated 3 years ago · GPL-3.0 GitHub repository of D/W/M VWAPs

LoD Intraday Entry

by ChartsLector
41 stars

This overlay indicator marks the current day's low and a suggested entry zone a fraction of daily ATR below that low. It compares daily volume with a volume moving average, plots daily SMA and EMA distance, and draws an optional ATR-width price cloud. Labels c

Indicator v6 Support & resistanceVolatility & bands
Updated 4 days ago · None stated GitHub repository of LoD Intraday Entry
11 stars

This indicator identifies and visualizes key support and resistance zones directly on the price chart using historical 1-hour bar evidence. It calculates zone strength by weighting price rejections, support-resistance flips, relative volume spikes, price gaps,

Indicator v6 Support & resistanceVolatility & bands
Updated 7 weeks ago · MIT GitHub repository of 1-Hour Key Level Heatmap

This overlay indicator marks Wyckoff-style buying and selling climaxes on the price chart. It filters trend with an exponential moving average and a higher-timeframe EMA, then flags accumulation or distribution when price and ATR sit relative to their swing av

Indicator v6 TrendVolatility & bands
Updated 1 year ago · MIT GitHub repository of Ultimate Wyckoff Indicator V3 (Refined)

More Volume scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers