This is one way to fix the above issue when non-trading days are included in the last three days:Hello, @SleepyZ I am happy to report that the script works nicely. It does seem to reset itself from Monday (D1) and etc, so on Monday the 2D and 3D lines do not show up unless I set N as 3 on Monday. Is there a way to automatically rolling back for the 3 days? It seems to roll automatically on futures though. Many thanks!

Here is an ONDEMAND chart with the current day a Monday displaying the Monday's developing vwap and the prior two trading daysCode:`#VWAP Anchored #20210522 Sleepyz - Usethinkscript request #20210525 Sleepyz - modified to handle when no trading days are involved within the last 3 days script v { input lookback = 1; def ymd = GetYYYYMMDD(); def dayCount = CompoundValue(1, if ymd != ymd[1] then dayCount[1] + 1 else dayCount[1], 0); def thisDay = (HighestAll(dayCount) - dayCount) ; def anchor = 1 + lookback ; def volumeSum = if thisDay <= anchor then CompoundValue(1, volumeSum[1] + volume, volume) else 0; def volumeVwapSum = if thisDay <= anchor then CompoundValue(1, volumeVwapSum[1] + volume * vwap, volume * vwap) else 0; def volumeVwap2Sum = if thisDay <= anchor then CompoundValue(1, volumeVwap2Sum[1] + volume * Sqr(vwap), volume * Sqr(vwap)) else 0; def price = volumeVwapSum / volumeSum; def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0)); plot VWAP = price; } #Day Separator input show_day_separator = yes; AddVerticalLine(show_day_separator and SecondsFromTime(0930) == 0, "", Color.BLUE, stroke = Curve.FIRM); input lookback = 0; plot v1 = v(lookback); plot v2 = v(lookback + 1); plot v3 = v(lookback + 2); v1.SetDefaultColor(Color.CYAN); v2.SetDefaultColor(Color.GREEN); v3.SetDefaultColor(Color.RED); v1.SetLineWeight(3); v2.SetLineWeight(3); v3.SetLineWeight(3); v3.SetStyle(Curve.LONG_DASH);`