@SleepyZ, this is a GREAT study, THANK YOU! May I request one modification?
You've
input startdate = 20211015;
input starttime = 0930;
Can you please include logic for the following four inputs
input startDateSelection = {default Daily, Custom} ; # where "Daily" would anchor vwap for each day and if "Custom" is chosen, it would go with the date specified in startDate and anchor from that day on (like what you have now)
input startTimeSelection = {default RTH, PRE, Custom} ; # where - while keeping startDate/Selection in mind, "RTH" would start anchored vwap at start of cash trading time, "Pre" would start at 4 AM ET, and "Custom" would take starttime as the anchor time (like what you have now)
input showOnlyToday = yes; #Where "Yes" would show vwap for only today (in which case, it would supersede startDateSelection /startDate selection)
input colorVWAP = yes; #Where "Yes" would show vwap line as Red if prior close is below the vwap and default color if it's above vwap.
This should help
Ruby:#VWAP Anchored to Date/Time input startdateselection = {default Daily, Custom}; input starttimeselection = {default RTH, PRE, Custom}; input showtodayonly = yes; input colorvwap = yes; input usehigher = {default current, higher}; input agg = AggregationPeriod.FIFTEEN_MIN; input startdate = 20211130; input starttime = 0930; def time = if starttimeselection == starttimeselection.RTH then 0930 else if starttimeselection == starttimeselection.PRE then 0400 else starttime; def ymd = GetYYYYMMDD(); def bn = BarNumber(); def c = close; def v = volume(period = agg); def vw = vwap(period = agg); def anchor; def volumesum; def volumevwapsum; def volumevwap2sum; def price; def deviation; if usehigher == usehigher.current and GetAggregationPeriod() < AggregationPeriod.DAY or usehigher == usehigher.higher and agg < AggregationPeriod.DAY { anchor = if startdateselection == startdateselection.Daily and ymd != ymd[1] or startdateselection == startdateselection.Custom and GetYYYYMMDD() < startdate then 0 else if SecondsFromTime(time)[1] <= 0 and SecondsFromTime(time) >= 0 then 1 else anchor[1]; volumesum = if (anchor) then volumesum[1] + volume else 0; volumevwapsum = if (anchor) then volumevwapsum[1] + volume * vwap else 0; volumevwap2sum = if (anchor) then volumevwap2sum[1] + volume * Sqr(vwap) else 0; price = volumevwapsum / volumesum; deviation = Sqrt(Max(volumevwap2sum / volumesum - Sqr(price), 0)); } else { anchor = if GetYYYYMMDD() >= startdate then 1 else 0; volumesum = if anchor then CompoundValue(1, volumesum[1] + v, v) else 0; volumevwapsum = if anchor then CompoundValue(1, volumevwapsum[1] + v * vw, v * vw) else 0; volumevwap2sum = if anchor then CompoundValue(1, volumevwap2sum[1] + v * Sqr(vw), v * Sqr(vw)) else 0; price = volumevwapsum / volumesum; deviation = Sqrt(Max(volumevwap2sum / volumesum - Sqr(price), 0)); } plot VWAP = if showtodayonly and startdateselection == startdateselection.Daily and !IsNaN(close(period = AggregationPeriod.DAY)[-1]) then Double.NaN else price; VWAP.AssignValueColor(if colorvwap and close[1] < VWAP then Color.RED else Color.CYAN); input showbands = yes; input numDev1 = 1.0; input numDev2 = 2.0; input numDev3 = 3.0; plot UpperBand1 = if !showbands then Double.NaN else VWAP + numDev1 * deviation; plot LowerBand1 = if !showbands then Double.NaN else VWAP - numDev1 * deviation; plot UpperBand2 = if !showbands then Double.NaN else VWAP + numDev2 * deviation; plot LowerBand2 = if !showbands then Double.NaN else VWAP - numDev2 * deviation; plot UpperBand3 = if !showbands then Double.NaN else VWAP + numDev3 * deviation; plot LowerBand3 = if !showbands then Double.NaN else VWAP - numDev3 * deviation; VWAP.SetDefaultColor(Color.CYAN); UpperBand1.SetDefaultColor(Color.GREEN); LowerBand1.SetDefaultColor(Color.RED); UpperBand2.SetDefaultColor(Color.GREEN); LowerBand2.SetDefaultColor(Color.RED); UpperBand3.SetDefaultColor(Color.GREEN); LowerBand3.SetDefaultColor(Color.RED); VWAP.HideBubble(); UpperBand1.HideBubble(); LowerBand1.HideBubble(); UpperBand2.HideBubble(); LowerBand2.HideBubble(); UpperBand3.HideBubble(); LowerBand3.HideBubble(); input showclouds = yes; AddCloud(if showclouds then UpperBand3 else Double.NaN, UpperBand2, Color.LIGHT_GREEN, Color.LIGHT_GREEN); AddCloud(if showclouds then LowerBand3 else Double.NaN, LowerBand2, Color.LIGHT_RED, Color.LIGHT_RED); input showbubblesline = yes; input bubblemoverVWAP_Labels = 5;#Hint bubblemoverVWAP_Labels: Number of Spaces bubble offset in expansion area def n = bubblemoverVWAP_Labels; def n1 = n + 1; AddChartBubble(showbubblesline and IsNaN(c[n]) and !IsNaN(c[n1]) , price[n1] , "V:\n" + Round(price[n1] , 2), Color.ORANGE); AddChartBubble(showbubblesline and IsNaN(c[n]) and !IsNaN(c[n1]) , price[n1] + numDev1 * deviation[n1] , "V1:\n" + Round((price[n1] + numDev1 * deviation[n1]), 2), Color.GREEN); AddChartBubble(showbubblesline and IsNaN(c[n]) and !IsNaN(c[n1]) , price[n1] + numDev2 * deviation[n1] , "V2:\n" + Round(price[n1] + numDev2 * deviation[n1], 2), Color.GREEN); AddChartBubble(showbubblesline and IsNaN(c[n]) and !IsNaN(c[n1]) , price[n1] + numDev3 * deviation[n1] , "V3:\n" + Round(price[n1] + numDev3 * deviation[n1], 2), Color.GREEN); AddChartBubble(showbubblesline and IsNaN(c[n]) and !IsNaN(c[n1]) , price[n1] - numDev1 * deviation[n1] , "V1:\n" + Round(price[n1] - numDev1 * deviation[n1], 2), Color.RED, no); AddChartBubble(showbubblesline and IsNaN(c[n]) and !IsNaN(c[n1]) , price[n1] - numDev2 * deviation[n1] , "V2:\n" + Round(price[n1] - numDev2 * deviation[n1] , 2), Color.RED, no); AddChartBubble(showbubblesline and IsNaN(c[n]) and !IsNaN(c[n1]) , price[n1] - numDev3 * deviation[n1] , "V3:\n" + Round(price[n1] - numDev3 * deviation[n1] , 2), Color.RED, no); input showbubblescurrSTD = no; input bubblemoverVSTD = 1;#Hint bubblemoverVSTD: Number of Spaces VSTD bubble offset in expansion def p = bubblemoverVSTD; def p1 = p + 1; AddChartBubble(showbubblescurrSTD and IsNaN(c[p]) and !IsNaN(c[p1]) , c[p1], Round(((c[p1] - price[p1]) / deviation[p1]), 1) + "\n" + Round(c[p1], 2) , if c[p1] > VWAP[p1] then Color.GREEN else Color.RED, if c[p1] > VWAP[p1] then yes else no );