1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.
Source Code
167 lines of Pine Script v5 from Tradingview/Anchored VWAP.pinescript, published under MIT. Keep the author's credit and licence lines when you reuse it.
Anchored VWAP.pinescript
//@version=5
//KAL @ MuMuLLC
indicator(title='Anchored VWAP', shorttitle='VWAP', overlay=true)
//Will work fine on range charts, use these configs.
anchor = input.string(defval='Month', title='Anchor Period', options=['Session', 'Week', 'Month', 'Year'])
MILLIS_IN_DAY = 86400000
dwmBarTime = timeframe.isdwm ? time : time('D')
// If it's a short day, then there could be no daily bar. Take a previous one.
if na(dwmBarTime)
dwmBarTime := nz(dwmBarTime[1])
dwmBarTime
var periodStart = time - time // zero
// in pine week starts on Sunday and it's value 1. Value of Monday is 2
// we need a week to start on Monday and its value should be 0
makeMondayZero(dayOfWeek) =>
(dayOfWeek + 5) % 7
isMidnight(t) =>
hour(t) == 0 and minute(t) == 0
isSameDay(t1, t2) =>
dayofmonth(t1) == dayofmonth(t2) and month(t1) == month(t2) and year(t1) == year(t2)
isOvernight() =>
not(isMidnight(dwmBarTime) or request.security(syminfo.tickerid, 'D', isSameDay(time, time_close), lookahead=barmerge.lookahead_on))
tradingDayStart(t) =>
y = year(t)
m = month(t)
d = dayofmonth(t)
timestamp(y, m, d, 0, 0)
numDaysBetween(time1, time2) =>
y1 = year(time1)
m1 = month(time1)
d1 = dayofmonth(time1)
y2 = year(time2)
m2 = month(time2)
d2 = dayofmonth(time2)
diff = math.abs(timestamp('GMT', y1, m1, d1, 0, 0) - timestamp('GMT', y2, m2, d2, 0, 0))
diff / MILLIS_IN_DAY
// a symbol with overnight session starts at previos day
// to get the trading day we should get the next day after the session's start
tradingDay = isOvernight() ? tradingDayStart(dwmBarTime + MILLIS_IN_DAY) : tradingDayStart(dwmBarTime)
isNewPeriod() =>
isNew = false
if tradingDay != nz(tradingDay[1])
if anchor == 'Session'
isNew := na(tradingDay[1]) or tradingDay > tradingDay[1]
isNew
if anchor == 'Week'
DAYS_IN_WEEK = 7
isNew := makeMondayZero(dayofweek(periodStart)) + numDaysBetween(periodStart, tradingDay) >= DAYS_IN_WEEK
isNew
if anchor == 'Month'
isNew := month(periodStart) != month(tradingDay) or year(periodStart) != year(tradingDay)
isNew
if anchor == 'Year'
isNew := year(periodStart) != year(tradingDay)
isNew
isNew
src = hlc3
sumSrc = float(na)
sumVol = float(na)
sumXtr = float(na)
sumSrc := nz(sumSrc[1], 0)
sumVol := nz(sumVol[1], 0)
sumXtr := nz(sumXtr[1], 0)
if isNewPeriod()
periodStart := tradingDay
sumSrc := 0.0
sumVol := 0.0
sumXtr := 0.0
sumXtr
if not na(src) and not na(volume)
sumSrc += src * volume
sumVol += volume
sumXtr += src * src * volume
sumXtr
vwapValue = sumSrc / sumVol
sigma = math.sqrt(math.max(sumXtr / sumVol - vwapValue * vwapValue, 0))
plot(vwapValue, title='Mean', color=color.new(#E1D13D, 0))
plot(vwapValue + sigma * 1, title='1 Sigma Above', color=color.new(#6AE12F, 0))
plot(vwapValue + sigma * 2, title='2 Sigma Above', color=color.new(#6AE12F, 0))
plot(vwapValue + sigma * 3, title='3 Sigma Above', color=color.new(#6AE12F, 0))
plot(vwapValue - sigma * 1, title='1 Sigma Below', color=color.new(#CC272A, 0))
plot(vwapValue - sigma * 2, title='2 Sigma Below', color=color.new(#CC272A, 0))
plot(vwapValue - sigma * 3, title='3 Sigma Below', color=color.new(#CC272A, 0))
Overview
Anchored VWAP accumulates the typical price (HLC3) weighted by volume and resets the calculation at the start of a session, week, month, or year. It also plots bands one, two, and three standard deviations above and below that mean. The only setting chooses the anchor period. Weekly anchors start on Monday, and overnight sessions shift the trading day. It reads daily data with lookahead enabled, so the anchor can use future daily information.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Anchor Period
string
Month
anchor
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.
The Momentum Setup is a multi-indicator visual tool designed for trend and momentum analysis directly on the price chart. It combines Relative Strength Index (RSI), Money Flow Index (MFI), Commodity Channel Index (CCI), Supertrend, and a 250-bar percentage cha
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
This indicator plots a volume-weighted average price and three standard-deviation bands on the price chart. It resets the running volume-weighted totals at the selected anchor, which can be the session, week, month, quarter, or year. The source price, band mul
LiqSpikeBounceLong Feb2026 is an indicator designed to identify long bounce entries following high-volume liquidation cascades in bearish market contexts. It checks if price is below an exponential moving average, then detects large single-bar drops exceeding
This indicator calculates Kaufman's Adaptive Moving Average (KAMA) on a chosen price source and determines trend direction based on the slope across a configurable lookback window. Signals can be filtered by short-term volatility expansion using ATR comparison
This indicator plots a volume-weighted average price on the price chart and resets the calculation when the selected session changes. It builds first and second standard-deviation bands from a volume-weighted variance of the chosen source, which defaults to th