Anchored VWAP Indicator for ThinkorSwim

@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

capture.jpg
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 );
 
  • Love
Reactions: bmn
This should help

This might 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 starttimeselection==starttimeselection.RTH
                     and gettime() crosses above regularTradingStart(getyyyyMMDD())       
                     or starttimeselection==starttimeselection.PRE
                     and gettime() crosses below regularTradingend(getyyyyMMDD()[1])
                     or starttimeselection==starttimeselection.Custom
                     and 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 );
 
Last edited:
  • Like
Reactions: bmn
(Will check it out in a bit,. but) should the first 'or' condition in the else-if of the 'anchor' definition be checking for startimeselection.RTH (or .PRE)? Also, for pre (when custom isn't used), can the start be after the rollover (aka, today am pre-market ). For pre, I don't want to consider the time between yesterday's close and day rollover.
 
(Will check it out in a bit,. but) should the first 'or' condition in the else-if of the 'anchor' definition be checking for startimeselection.RTH (or .PRE)? Also, for pre (when custom isn't used), can the start be after the rollover (aka, today am pre-market ). For pre, I don't want to consider the time between yesterday's close and day rollov

The first cond is RTH. The second has now been edited above to be PRE. Please use custom for any other time you want.
 
  • Like
Reactions: bmn
The first cond is RTH. The second has now been edited above to be PRE. Please use custom for any other time you want.
Thanks @SleepyZ !!

I'm test driving the updated version and seeing something strange. For tickers like SPY/AAPL, the PRE selection is working (5D 5m chart). However, for tickers like ROKU and BA, it's not plotting anything.
 
Thanks @SleepyZ !!

I'm test driving the updated version and seeing something strange. For tickers like SPY/AAPL, the PRE selection is working (5D 5m chart). However, for tickers like ROKU and BA, it's not plotting anything.
Try using the above code that I just edited changing for PRE, the gettime() above to gettime() below
 
  • Like
Reactions: bmn
Try using the above code that I just edited changing for PRE, the gettime() above to gettime() below
That WORKED!! Thank you

Just one very minor thing.. sorry (do you use discord? Maybe that might be a better instead of seeing my many comments here.. haha)
Not sure if it's because "crosses" is used or [1], but) whenever PRE is selected, the plotting starts from the 2nd bar of whatever the aggregation chart is on. e.g. on /cl 1d 1m chart, the plotting starts from 18:01 PM EST instead of 18:00 PM EST. On AAPL 5D 5m, the PRE plotting starts from 04:05 AM EST instead of 04:00 AM EST.

For RTH, the plotting starts from the first bar. (y)
 
That WORKED!! Thank you

Just one very minor thing.. sorry (do you use discord? Maybe that might be a better instead of seeing my many comments here.. haha)
Not sure if it's because "crosses" is used or [1], but) whenever PRE is selected, the plotting starts from the 2nd bar of whatever the aggregation chart is on. e.g. on /cl 1d 1m chart, the plotting starts from 18:01 PM EST instead of 18:00 PM EST. On AAPL 5D 5m, the PRE plotting starts from 04:05 AM EST instead of 04:00 AM EST.

For RTH, the plotting starts from the first bar. (y)

I hopefully fixed PRE and put the fix in the code above. The last secondsfromtime condition was conflicting with the PRE code, so I specified that to be only when Custom time was chosen.

I am not on discord.
 
I hopefully fixed PRE and put the fix in the code above. The last secondsfromtime condition was conflicting with the PRE code, so I specified that to be only when Custom time was chosen.

I am not on discord.

Thanks for taking another look. Unfortunately, still seeing same behavior. But it's ok, not a big deal. Thanks again for all the updates.
 
Thanks for taking another look. Unfortunately, still seeing same behavior. But it's ok, not a big deal. Thanks again for all the updates.

Thanks for letting me know. I think the followiing starts properly at PRE time and seems to work properly otherwise. These lines fixed the plot for PRE as the Daily part of the code needed to start at 0, which excluded it to plot for PRE and was not a problem for RTH code.

Ruby:
    volumesum      = if if starttimeselection==starttimeselection.PRE then anchor[-1] else anchor  then volumesum[1] + volume else 0;
    volumevwapsum  = if if starttimeselection==starttimeselection.PRE then anchor[-1] else anchor  then volumevwapsum[1] + volume * vwap else 0;
    volumevwap2sum = if  if starttimeselection==starttimeselection.PRE then anchor[-1] else anchor  then volumevwap2sum[1] + volume * Sqr(vwap) else 0;

Here is the full code with this change included
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 starttimeselection==starttimeselection.RTH
                     and gettime() crosses above regularTradingStart(getyyyyMMDD())       
                     or starttimeselection==starttimeselection.PRE
                     and gettime() crosses below regularTradingend(getyyyyMMDD()[1])
                     or starttimeselection==starttimeselection.Custom
                     and SecondsFromTime(time)[1] <= 0 and
                         SecondsFromTime(time) >= 0
                     then 1
                     else anchor[1];

    volumesum      = if if starttimeselection==starttimeselection.PRE then anchor[-1] else anchor  then volumesum[1] + volume else 0;
    volumevwapsum  = if if starttimeselection==starttimeselection.PRE then anchor[-1] else anchor  then volumevwapsum[1] + volume * vwap else 0;
    volumevwap2sum = if  if starttimeselection==starttimeselection.PRE then anchor[-1] else 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 );
 
  • Love
Reactions: bmn
Thanks for letting me know. I think the followiing starts properly at PRE time and seems to work properly otherwise. These lines fixed the plot for PRE as the Daily part of the code needed to start at 0, which excluded it to plot for PRE and was not a problem for RTH code.



Here is the full code with this change included
This WORKED!! Appreciate the persistence.

One new thing I just noticed is that when Extended Hours setting for futures is turned off and I choose Dec 1st as custom date and RTH as time or 800 as custom time (for \CL 15D 5m chart), it doesn't plot. Strangely, when Pre is selected, it plots from Dec 1st 9AM EST onwards..
Seeing similar for $AAPL (when Daily is chosen, it doesn't plot anything either).
Seeing only the cloud (no lines) and bubbles for these tickers when extended hours is off, custom date of dec 1st and PRE is selected.

In all cases, getting the following error: "Trying to self-assign a non-initialized rec: anchor."
 
This WORKED!! Appreciate the persistence.

One new thing I just noticed is that when Extended Hours setting for futures is turned off and I choose Dec 1st as custom date and RTH as time or 800 as custom time (for \CL 15D 5m chart), it doesn't plot. Strangely, when Pre is selected, it plots from Dec 1st 9AM EST onwards..
Seeing similar for $AAPL (when Daily is chosen, it doesn't plot anything either).
Seeing only the cloud (no lines) and bubbles for these tickers when extended hours is off, custom date of dec 1st and PRE is selected.

In all cases, getting the following error: "Trying to self-assign a non-initialized rec: anchor."
It is not going to work for the most part if you do any of the Daily settings of RTH or PRE with extended hours turned off as I have used gettime() crossing in relation to regular trading hours. If extended hours is turned off there is no crossing, so unreliable or no results. As this script has evolved beyond what the original intent that I scripted, I do not wish to revise this script any further as there is enough to work around most problems. Nonetheless, I am using this script and find it personally very useful.
 
  • Like
Reactions: bmn
It is not going to work for the most part if you do any of the Daily settings of RTH or PRE with extended hours turned off as I have used gettime() crossing in relation to regular trading hours. If extended hours is turned off there is no crossing, so unreliable or no results. As this script has evolved beyond what the original intent that I scripted, I do not wish to revise this script any further as there is enough to work around most problems. Nonetheless, I am using this script and find it personally very useful.
Thanks for explaining the cause. And I understand, will use it with Extended Hours turned on. Thanks again for all the updates.
 
Here is a scan for stocks that crosses ABOVE the previous day's VWAP. Place this code in the scanner and run this on a daily aggregation. I just ran this on the S&P 100 (Daily) and obtained 46 results

Code:
# Scan for crosses above previous day's VWAP
# tomsk
# 1.21.2020

# Run on a daily aggregation

def cap = getAggregationPeriod();
def yyyyMmDd = getYyyyMmDd();
def periodIndx = yyyyMmDd;
def isPeriodRolled = compoundValue(1, periodIndx != periodIndx[1], yes);

def volumeSum;
def volumeVwapSum;
def volumeVwap2Sum;

if (isPeriodRolled) {
    volumeSum = volume;
    volumeVwapSum = volume * vwap;
    volumeVwap2Sum = volume * Sqr(vwap);
} else {
    volumeSum = compoundValue(1, volumeSum[1] + volume, volume);
    volumeVwapSum = compoundValue(1, volumeVwapSum[1] + volume * vwap, volume * vwap);
    volumeVwap2Sum = compoundValue(1, volumeVwap2Sum[1] + volume * Sqr(vwap), volume * Sqr(vwap));
}
def price = volumeVwapSum / volumeSum;
def VWAP = price;

plot scan = close crosses above VWAP[1];
# End Scan for crosses above previous day's VWAP
Hello Tomsk, To Scan for VWAP above 2 SD away is this the only line (plot scan = close crosses above VWAP[1]; ) that needs to be changed to:
plot scan = close crosses above VWAP[2]; or there are other areas of code that needs to be changed? Also to Scan for Crosses on the down side, is this what we need: plot scan = close crosses below VWAP[1]; ?
 
Hello Tomsk, To Scan for VWAP above 2 SD away is this the only line (plot scan = close crosses above VWAP[1]; ) that needs to be changed to:
plot scan = close crosses above VWAP[2]; or there are other areas of code that needs to be changed? Also to Scan for Crosses on the down side, is this what we need: plot scan = close crosses below VWAP[1]; ?
The script you are attempting to use is scanning for close crossing above VWAP[1] meaning close crossing above the previous VWAP candle. If you change it to VWAP[2], it would mean you are scanning for close crossing above the VWAP of 2 bars ago.

If that is what you are looking for then yep, go for it.
 
It is not going to work for the most part if you do any of the Daily settings of RTH or PRE with extended hours turned off as I have used gettime() crossing in relation to regular trading hours. If extended hours is turned off there is no crossing, so unreliable or no results. As this script has evolved beyond what the original intent that I scripted, I do not wish to revise this script any further as there is enough to work around most problems. Nonetheless, I am using this script and find it personally very useful.
I am new I am sorry if I am posting it in wrong space. I need help with this intraday AWAP code, please help with I need three mods :
1. AnchorTime should automaticaly be HOD candle of 5 min.
2. Anchordate by default to be today's date.
3. If possible to draw two awap lines one anchored to HOD and the other LOD , right now I am running too study same code but with differnt color line and keep changing the anchortime and date.
Thankyou in advance.
**************************************************************
input anchorDate = 20220103;
input anchorTime = 930;

def postAnchorDate = if GetYYYYMMDD() >= anchorDate then 1 else 0;
def postAnchorTime = if SecondsTillTime(anchorTime) == 0 then 1 else if GetYYYYMMDD() < AnchorDate then 0 else postAnchorTime[1];

plot anchoredVWAP = TotalSum(if postAnchorDate and postAnchorTime then ((high + low + close) / 3) * (volume) else 0) / TotalSum(if postAnchorDate and postAnchorTime then volume else 0);

anchoredVWAP.SetStyle(Curve.FIRM);
anchoredVWAP.SetLineWeight(3);
anchoredVWAP.SetDefaultColor(Color.CYAN);
********************************************************************************************************
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
388 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top