VWAP Crosses, Format, Watchlist, Label, Scan for ThinkorSwim

Please check this one

def vwap = reference vwap();
plot scan = close[-1] < vwap[-1] and close[1] > vwap[1];

Again, I think crosses above also will also serve the purpose - like below:

def vwap = reference vwap();
plot scan = close crosses above vwap;
@Joby would this scan for crossing above and below?
 

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

@TapthaAsk

you need another scan for crossing below like:

def vwap = reference vwap();
plot scan = close crosses below vwap;
 
Hi... trying to understand exactly what just one line here is doing....
Is it plotting the moving average of VWAP?
The question is repeated in the code as comments.

Code:
## Start Code

    input vwap_price = FundamentalType.VWAP;
    input vwap_aggregationPeriod = AggregationPeriod.FOUR_HOURS; 
    input vwap_barOffset = 0;

    input vwap_length = 3; # X

    #### I think... this is a moving avg of VWAP where X is the number of periods (aggregation periods) back.
    ### so.. .a value of X = 1 will just show the VWAP for each 4 hour period.
    ### 

    ##################### is that wat this line does?
    plot longVWAP;

    longVWAP = Average(fundamental(vwap_price, period = vwap_aggregationPeriod)[vwap_barOffset], vwap_length);   
      
    ##################### END: is that wat this line does?


    longVWAP.SetDefaultColor(COLOR.ORANGE);
    longVWAP.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

## End Code
 
Hi... trying to understand exactly what just one line here is doing....
Is it plotting the moving average of VWAP?
The question is repeated in the code as comments.

Code:
## Start Code

    input vwap_price = FundamentalType.VWAP;
    input vwap_aggregationPeriod = AggregationPeriod.FOUR_HOURS;
    input vwap_barOffset = 0;

    input vwap_length = 3; # X

    #### I think... this is a moving avg of VWAP where X is the number of periods (aggregation periods) back.
    ### so.. .a value of X = 1 will just show the VWAP for each 4 hour period.
    ###

    ##################### is that wat this line does?
    plot longVWAP;

    longVWAP = Average(fundamental(vwap_price, period = vwap_aggregationPeriod)[vwap_barOffset], vwap_length);  
     
    ##################### END: is that wat this line does?


    longVWAP.SetDefaultColor(COLOR.ORANGE);
    longVWAP.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

## End Code
yes
 
The VWAP indicator that comes with TOS offers aggregation periods of DAY, WEEK, MONTH, and try as I might I cannot add a YEAR to the options for selection.
Is it possible to even add YEAR to the VWAP?
If possible, could someone please ..... I am extremely grateful for all your help.
 
The VWAP indicator that comes with TOS offers aggregation periods of DAY, WEEK, MONTH, and try as I might I cannot add a YEAR to the options for selection.
Is it possible to even add YEAR to the VWAP?
If possible, could someone please ..... I am extremely grateful for all your help.

Here is modified TOS VWAP indicator with additional timeframes added

Capture.jpg
Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2011-2022
#
#Modified Timeframes

input numDevDn = -2.0;
input numDevUp = 2.0;
input timeFrame = {default CHART, MINUTE, HOUR, DAY, WEEK, MONTH, "OPT EXP", BAR, QUARTER, YEAR};

def cap = GetAggregationPeriod();
def errorInAggregation =
    timeFrame == timeFrame.DAY and cap >= AggregationPeriod.WEEK or
    timeFrame == timeFrame.WEEK and cap >= AggregationPeriod.MONTH;
Assert(!errorInAggregation, "timeFrame should be not less than current chart aggregation period");

def yyyyMmDd = GetYYYYMMDD();
def period ;
def seconds = secondsFromTime(0);
def year = getYear();
def month = year * 12 + getMonth();
def day_number = daysFromDate(first(yyyymmdd)) + getDayOfWeek(first(yyyymmdd));
def dom = getDayOfMonth(yyyymmdd);
def dow = getDayOfWeek(yyyymmdd - dom + 1);
def expthismonth = (if dow > 5 then 27 else 20) - dow;
def exp_opt = month + (dom > expthismonth);
def periodMin = Floor(seconds / 60 + day_number * 24 * 60);
def periodHour = Floor(seconds / 3600 + day_number * 24);
def periodDay = countTradingDays(Min(first(yyyymmdd), yyyymmdd), yyyymmdd) - 1;
def periodWeek = Floor(day_number / 7);
def periodMonth = month - first(month);
def periodQuarter = Ceil(month / 3) - first(Ceil(month / 3));
def periodYear = year - first(year);

switch (timeFrame) {
case CHART:
    period = 0;
case MINUTE:
    period = periodMin;
case HOUR:
    period = periodHour;
case DAY:
    period = periodDay;
case WEEK:
    period = periodWeek;
case MONTH:
    period = periodMonth;
case "OPT EXP":
    period = exp_opt - First(exp_opt);
case BAR:
    period = BarNumber() - 1;
case QUARTER:
period = Ceil(month / 3) - first(Ceil(month / 3));
case YEAR:
    period = periodYear;
}

def isPeriodRolled = CompoundValue(1, period != period[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 deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));

plot VWAP = price;
plot UpperBand = price + numDevUp * deviation;
plot LowerBand = price + numDevDn * deviation;

VWAP.SetDefaultColor(GetColor(0));
UpperBand.SetDefaultColor(GetColor(2));
LowerBand.SetDefaultColor(GetColor(4));
 
Wow ... AWSOME.
Thank you so much. This is even more than I was hoping for.

Here is the above script with a multiplier added. It will allow you to choose how many multiples of a given timeframe selected together. For example, input multiplier = 3 and Day will display a 2 Day VWAP.

Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2011-2022
#
#Modified Timeframes

input numDevDn = -2.0;
input numDevUp = 2.0;
input timeFrame = {default CHART, MINUTE, HOUR, DAY, WEEK, MONTH, "OPT EXP", BAR, QUARTER, YEAR};
input multiplier = 1;#Enter number of timeframes to show together (eg: 2Days; 45Minutes, ets)

def cap = GetAggregationPeriod();
def errorInAggregation =
    timeFrame == timeFrame.DAY and cap >= AggregationPeriod.WEEK or
    timeFrame == timeFrame.WEEK and cap >= AggregationPeriod.MONTH;
Assert(!errorInAggregation, "timeFrame should be not less than current chart aggregation period");

def yyyyMmDd = GetYYYYMMDD();
def period ;
def seconds = secondsFromTime(0);
def year = getYear();
def month = year * 12 + getMonth();
def day_number = daysFromDate(first(yyyymmdd)) + getDayOfWeek(first(yyyymmdd));
def dom = getDayOfMonth(yyyymmdd);
def dow = getDayOfWeek(yyyymmdd - dom + 1);
def expthismonth = (if dow > 5 then 27 else 20) - dow;
def exp_opt = month + (dom > expthismonth);
def periodMin = Floor(seconds / 60 + day_number * 24 * 60);
def periodHour = Floor(seconds / 3600 + day_number * 24);
def periodDay = countTradingDays(Min(first(yyyymmdd), yyyymmdd), yyyymmdd) - 1;
def periodWeek = Floor(day_number / 7);
def periodMonth = month - first(month);
def periodQuarter = Ceil(month / 3) - first(Ceil(month / 3));
def periodYear = year - first(year);

switch (timeFrame) {
case CHART:
    period = 0;
case MINUTE:
    period = periodMin;
case HOUR:
    period = periodHour;
case DAY:
    period = periodDay;
case WEEK:
    period = periodWeek;
case MONTH:
    period = periodMonth;
case "OPT EXP":
    period = exp_opt - First(exp_opt);
case BAR:
    period = BarNumber() - 1;
case QUARTER:
period = Ceil(month / 3) - first(Ceil(month / 3));
case YEAR:
    period = periodYear;
}

def count = compoundvalue(1, if period != period[1] then (getValue(count, 1) + period - period[1]) % multiplier else getValue(count, 1), 0);
def isPeriodRolled = compoundvalue(1, count < count[1] + period - period[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 deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));

plot VWAP = price;
plot UpperBand = price + numDevUp * deviation;
plot LowerBand = price + numDevDn * deviation;

VWAP.SetDefaultColor(GetColor(0));
UpperBand.SetDefaultColor(GetColor(2));
LowerBand.SetDefaultColor(GetColor(4));
 
Hi all!

I am on new on the forum and new to scripts but i have been trading for a year.

I want to make a script where it buys everytime it hits the lower band of the vwap i enter a long with tp on the vwap line. And short when it hits upper band and tp when it hits the vwap as a base for my strategy.

I can't seem to figure it out, can anyone help me?


Would appreciate it a lot
 
Hi all!

I am on new on the forum and new to scripts but i have been trading for a year.

I want to make a script where it buys everytime it hits the lower band of the vwap i enter a long with tp on the vwap line. And short when it hits upper band and tp when it hits the vwap as a base for my strategy.

I can't seem to figure it out, can anyone help me?


Would appreciate it a lot

This may give you some ideas. The image is GME 3D 3min chart. Various timeframes have significantly different profit and loss.

Capture.jpg
Ruby:
input num_std_dev = 2.0;
plot vwapupper = reference VWAP("num dev dn" = -num_std_dev, "num dev up" = num_std_dev).UpperBand;
plot vwap      = reference VWAP();
plot vwaplower = reference VWAP("num dev dn" = -num_std_dev, "num dev up" = num_std_dev).LowerBand;

#Orders Limited to Regular Trading Hours
def rth = Between(GetTime(), RegularTradingStart(GetYYYYMMDD()),  RegularTradingEnd(GetYYYYMMDD()));       

#Buy Orders                             
AddOrder(OrderType.BUY_TO_OPEN,
         rth and low crosses below vwaplower,
         tickColor = Color.GREEN, arrowColor = Color.GREEN,
         name = "Buy to Open");
AddOrder(OrderType.SELL_TO_CLOSE,
         rth and close crosses vwap,
         tickColor = Color.WHITE, arrowColor = Color.WHITE,
         name = "Seel to Close");

#Sell Orders
AddOrder(OrderType.SELL_TO_OPEN,
         rth and high crosses above vwapupper,
         tickColor = Color.RED, arrowColor = Color.RED,
         name = "sell to open");
AddOrder(OrderType.BUY_TO_CLOSE,
         rth and close crosses vwap,
         tickColor = Color.WHITE, arrowColor = Color.WHITE,
         name = "buy to close");
 
Hi team,

I found this anchorVWAP script on the web which is very useful and was wondering if you're able to create a label for this indicator? Thanks in advance.

declare hide_on_daily;

def anchorTime = 0930;
def anchorEnd = 1600;

input ShowTodayOnly = yes;
def Today = if GetDay() == GetLastDay() then 1 else 0;
def postAnchorTime = if SecondsFromTime(anchorTime) >= 0 then 1 else 0;
def endAchorTime = if SecondsTillTime(anchorEnd) >= 0 then 1 else 0;
def volumeSum2 = compoundValue(1, if postAnchorTime and endAchorTime then volumeSum2[1] + volume else 0, volume);
def volumeVwapSum2 = compoundValue(1, if postAnchorTime and endAchorTime then volumeVwapSum2[1] + volume * vwap else 0, volume * vwap);

plot anchorVWAP = if ShowTodayOnly and !Today then Double.NaN else if anchorTime then volumeVwapSum2 / volumeSum2 else Double.NaN;
anchorVWAP.setStyle(Curve.Firm);
anchorVWAP.setDefaultColor(Color.light_ORANGE);
anchorVWAP.setlineWeight(2);
 
Hi team,

I found this anchorVWAP script on the web which is very useful and was wondering if you're able to create a label for this indicator? Thanks in advance.

declare hide_on_daily;

def anchorTime = 0930;
def anchorEnd = 1600;

input ShowTodayOnly = yes;
def Today = if GetDay() == GetLastDay() then 1 else 0;
def postAnchorTime = if SecondsFromTime(anchorTime) >= 0 then 1 else 0;
def endAchorTime = if SecondsTillTime(anchorEnd) >= 0 then 1 else 0;
def volumeSum2 = compoundValue(1, if postAnchorTime and endAchorTime then volumeSum2[1] + volume else 0, volume);
def volumeVwapSum2 = compoundValue(1, if postAnchorTime and endAchorTime then volumeVwapSum2[1] + volume * vwap else 0, volume * vwap);

plot anchorVWAP = if ShowTodayOnly and !Today then Double.NaN else if anchorTime then volumeVwapSum2 / volumeSum2 else Double.NaN;
anchorVWAP.setStyle(Curve.Firm);
anchorVWAP.setDefaultColor(Color.light_ORANGE);
anchorVWAP.setlineWeight(2);

As you did not indicate what you wanted in the labels, here are 2 labels added to your code to get you started.

Code:
declare hide_on_daily;

def anchorTime = 0930;
def anchorEnd = 1600;

input ShowTodayOnly = yes;
def Today = if GetDay() == GetLastDay() then 1 else 0;
def postAnchorTime = if SecondsFromTime(anchorTime) >= 0 then 1 else 0;
def endAchorTime = if SecondsTillTime(anchorEnd) >= 0 then 1 else 0;
def volumeSum2 = CompoundValue(1, if postAnchorTime and endAchorTime then volumeSum2[1] + volume else 0, volume);
def volumeVwapSum2 = CompoundValue(1, if postAnchorTime and endAchorTime then volumeVwapSum2[1] + volume * vwap else 0, volume * vwap);

plot anchorVWAP = if ShowTodayOnly and !Today then Double.NaN else if anchorTime then volumeVwapSum2 / volumeSum2 else Double.NaN;
anchorVWAP.SetStyle(Curve.FIRM);
anchorVWAP.SetDefaultColor(Color.LIGHT_ORANGE);
anchorVWAP.SetLineWeight(2);

AddLabel(1, "VWAP",
            if anchorVWAP > anchorVWAP[1]
            then Color.GREEN
            else Color.RED);
AddLabel(1, if close > anchorVWAP
            then "Close>VWAP"
            else "Close<VWAP",
            if close > anchorVWAP
            then Color.GREEN
            else Color.RED);
 
Hi SleepyZ,

Thanks for the kind response. I like the idea of the second label option that changes color based on the closing candles but for some reason none of the label options you've provided are working. Will it be because the session is closed? All I see are black color labels with no values.


Additional request:

Are you able to add deviations using inputs as the below info with each respective label (based on label option# 2) just like the anchorVWAP?

input numDevUp1 = 1.0;
input numDevUP2 = 2.0;
input numDevUP3 = 3.0;
input numDevDn1 = -1.0;
input numDevDn2 = -2.0;
input numDevDn3 = -3.0;

plot UpperBand1 =
plot UpperBand2 =
plot UpperBand3 =
plot anchorVWAP =
plot LowerBand1 =
plot LowerBand2 =
plot LowerBand3 =
 
Hi SleepyZ,

Thanks for the kind response. I like the idea of the second label option that changes color based on the closing candles but for some reason none of the label options you've provided are working. Will it be because the session is closed? All I see are black color labels with no values.


Additional request:

Are you able to add deviations using inputs as the below info with each respective label (based on label option# 2) just like the anchorVWAP?

input numDevUp1 = 1.0;
input numDevUP2 = 2.0;
input numDevUP3 = 3.0;
input numDevDn1 = -1.0;
input numDevDn2 = -2.0;
input numDevDn3 = -3.0;

plot UpperBand1 =
plot UpperBand2 =
plot UpperBand3 =
plot anchorVWAP =
plot LowerBand1 =
plot LowerBand2 =
plot LowerBand3 =

Yes, the labels only show during regular trading hours.

Here is your request

Ruby:
declare hide_on_daily;

def anchorbegin = 0930;
def anchorEnd   = 1600;

input ShowTodayOnly = no;
def Today           = if GetDay() == GetLastDay() then 1 else 0;

def rth             = SecondsFromTime(anchorbegin) >= 0 and
                      SecondsTillTime(anchorEnd) >= 0;

def volumeSum       = if showtodayonly and !today
                      then double.nan
                      else if rth
                      then volumeSum[1] + volume
                      else 0;
def volumeVwapSum   = if showtodayonly and !today
                      then double.nan
                      else if rth
                      then volumeVwapSum[1] + volume * vwap
                      else 0;
def volumeVwap2Sum  = if showtodayonly and !today
                      then double.nan
                      else if rth
                      then VolumeVwap2Sum[1] + volume * Sqr(vwap)
                      else 0;
def price           = volumeVwapSum / volumeSum;
def deviation       = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));

plot anchorVWAP     = price;
anchorVWAP.SetStyle(Curve.FIRM);
anchorVWAP.SetDefaultColor(Color.LIGHT_ORANGE);
anchorVWAP.SetLineWeight(2);

input numDevUp1 = 1.0;
input numDevUP2 = 2.0;
input numDevUP3 = 3.0;
input numDevDn1 = -1.0;
input numDevDn2 = -2.0;
input numDevDn3 = -3.0;

plot UpperBand1 = anchorVWAP + numDevUp1 * deviation;
plot UpperBand2 = anchorVWAP + numDevUP2 * deviation;
plot UpperBand3 = anchorVWAP + numDevUP3 * deviation;

plot LowerBand1 = anchorVWAP + numDevDn1 * deviation;
plot LowerBand2 = anchorVWAP + numDevDn2 * deviation;
plot LowerBand3 = anchorVWAP + numDevDn3 * deviation;

AddLabel(1, if close > UpperBand3
            then "Close>Upper3"
            else "Close<Upper3",
            if close > UpperBand3
            then Color.GREEN
            else Color.RED);

AddLabel(1, if close > UpperBand2
            then "Close>Upper2"
            else "Close<Upper2",
            if close > UpperBand2
            then Color.GREEN
            else Color.RED);

AddLabel(1, if close > UpperBand1
            then "Close>Upper1"
            else "Close<Upper1",
            if close > UpperBand1
            then Color.GREEN
            else Color.RED);

addlabel(1, " ", color.black);

AddLabel(1, if close > anchorVWAP
            then "Close>VWAP"
            else "Close<VWAP",
            if close > anchorVWAP
            then Color.GREEN
            else Color.RED);

addlabel(1, " ", color.black);

AddLabel(1, if close > LowerBand1
            then "Close>Lower1"
            else "Close<Lower1",
            if close > LowerBand1
            then Color.GREEN
            else Color.RED);

AddLabel(1, if close > LowerBand2
            then "Close>Lower2"
            else "Close<Lower2",
            if close > LowerBand2
            then Color.GREEN
            else Color.RED);

AddLabel(1, if close > LowerBand3
            then "Close>Lower3"
            else "Close<Lower3",
            if close > LowerBand3
            then Color.GREEN
            else Color.RED);
#
 
Awesome! Can't wait till Monday to see how it works but is there anyway possible this could work to reflect the last history or period based on the last closed value? And thanks for all of the great work. You are truly awesome!
 
Awesome! Can't wait till Monday to see how it works but is there anyway possible this could work to reflect the last history or period based on the last closed value? And thanks for all of the great work. You are truly awesome!

You can test this in ONDemand. See image below.

I am not sure what what exactly you are requesting (labels, bubbles, something else) above to relect the last history or period.

 
I'm not sure if this mod has been posted already as it's a lengthy thread and also seeing this being active again, I'd like to share my mod of this column indicator based off the original authors' code that I did shortly it was posted. The mod allows a quick sorting of the column per the status of the price-vwap relationship; original code sorts it via ticker price. It's also a bit cleaner imo.

dRP69vD.png


Modified code

Code:
# Vwap as watchlist column
# Credits WalkingBallista, BenTen
## Mod NeoEon
## Mod benefits: allows sorting based on price-vwap status
## Requsite: use daily aggregation

# Code Start

def vwap = vwap();

plot status = if close >= vwap then 1 else 0;

status.AssignValueColor(if status == 1 then
Color.DARK_Green else Color.DARK_Red);

AssignBackgroundCOlor(if status == 1 then Color.Dark_Green else Color.Dark_Red);

# Code End

## Source: https://usethinkscript.com/threads/vwap-crosses-format-watchlist-label-scan-for-thinkorswim.110/

If one can only have one indicator intraday, VWAP should be it.
 
You can test this in ONDemand. See image below.

I am not sure what what exactly you are requesting (labels, bubbles, something else) above to relect the last history or period.
Can the value of each price bubble shown on the right axis be reflected on each perspective label created? Please see the attached for your reference.

 
Last edited by a moderator:
Can the value of each price bubble shown on the right axis be reflected on each perspective label created? Please see the attached for your reference.


Added values to labels. Now can turn on/off labels, as optional bubbles were added

Capture.jpg
Ruby:
declare hide_on_daily;

def anchorbegin = 0930;
def anchorEnd   = 1600;

input ShowTodayOnly = no;
def Today           = if GetDay() == GetLastDay() then 1 else 0;

def rth             = SecondsFromTime(anchorbegin) >= 0 and
                      SecondsTillTime(anchorEnd) >= 0;

def volumeSum       = if ShowTodayOnly and !Today
                      then Double.NaN
                      else if rth
                      then volumeSum[1] + volume
                      else 0;
def volumeVwapSum   = if ShowTodayOnly and !Today
                      then Double.NaN
                      else if rth
                      then volumeVwapSum[1] + volume * vwap
                      else 0;
def volumeVwap2Sum  = if ShowTodayOnly and !Today
                      then Double.NaN
                      else if rth
                      then volumeVwap2Sum[1] + volume * Sqr(vwap)
                      else 0;
def price           = volumeVwapSum / volumeSum;
def deviation       = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));

plot anchorVWAP     = price;
anchorVWAP.SetStyle(Curve.FIRM);
anchorVWAP.SetDefaultColor(Color.LIGHT_ORANGE);
anchorVWAP.SetLineWeight(2);

input numDevUp1 = 1.0;
input numDevUP2 = 2.0;
input numDevUP3 = 3.0;
input numDevDn1 = -1.0;
input numDevDn2 = -2.0;
input numDevDn3 = -3.0;

plot UpperBand1 = anchorVWAP + numDevUp1 * deviation;
plot UpperBand2 = anchorVWAP + numDevUP2 * deviation;
plot UpperBand3 = anchorVWAP + numDevUP3 * deviation;

plot LowerBand1 = anchorVWAP + numDevDn1 * deviation;
plot LowerBand2 = anchorVWAP + numDevDn2 * deviation;
plot LowerBand3 = anchorVWAP + numDevDn3 * deviation;

input labels = yes;
AddLabel(labels, (if close > UpperBand3
                 then "Close>Upper3"
                 else "Close<Upper3") + "  " + AsText(UpperBand3),
                 if close > UpperBand3
                 then Color.GREEN
                 else Color.RED);

AddLabel(labels, (if close > UpperBand2
                 then "Close>Upper2"
                 else "Close<Upper2")  + "  " + AsText(UpperBand2),
                 if close > UpperBand2
                 then Color.GREEN
                 else Color.RED);

AddLabel(labels, (if close > UpperBand1
                 then "Close>Upper1"
                 else "Close<Upper1") + "  " + AsText(UpperBand1),
                 if close > UpperBand1
                 then Color.GREEN
                 else Color.RED);

AddLabel(labels, " ", Color.BLACK);

AddLabel(labels, (if close > anchorVWAP
                 then "Close>VWAP"
                 else "Close<VWAP") + "  " + AsText(anchorVWAP),
                 if close > anchorVWAP
                 then Color.GREEN
                 else Color.RED);

AddLabel(labels, " ", Color.BLACK);

AddLabel(labels, (if close > LowerBand1
                 then "Close>Lower1"
                 else "Close<Lower1")  + "  " + AsText(LowerBand1),
                 if close > LowerBand1
                 then Color.GREEN
                 else Color.RED);

AddLabel(labels, (if close > LowerBand2
                 then "Close>Lower2"
                 else "Close<Lower2")  + "  " + AsText(LowerBand2),
                 if close > LowerBand2
                 then Color.GREEN
                 else Color.RED);

AddLabel(labels, (if close > LowerBand3
                 then "Close>Lower3"
                 else "Close<Lower3") + "  " + AsText(LowerBand3),
                 if close > LowerBand3
                 then Color.GREEN
                 else Color.RED);

input bubbles = yes;
input bubblemover = 3;
def bm = bubblemover;
def bm1 = bm + 1;
AddChartBubble(IsNaN(close[bm]) and !IsNaN(close[bm1]), UpperBand1[bm1], "UB1", if close[bm1] > UpperBand1[bm1] then Color.GREEN else Color.RED);
AddChartBubble(IsNaN(close[bm]) and !IsNaN(close[bm1]), UpperBand2[bm1], "UB2", if close[bm1] > UpperBand2[bm1] then Color.GREEN else Color.RED);
AddChartBubble(IsNaN(close[bm]) and !IsNaN(close[bm1]), UpperBand3[bm1], "UB3", if close[bm1] > UpperBand3[bm1] then Color.GREEN else Color.RED);
AddChartBubble(IsNaN(close[bm]) and !IsNaN(close[bm1]), anchorVWAP[bm1], "VWAP", if close[bm1] > anchorVWAP[bm1] then Color.GREEN else Color.RED);

AddChartBubble(IsNaN(close[bm]) and !IsNaN(close[bm1]), LowerBand1[bm1], "LB1", if close[bm1] > LowerBand1[bm1] then Color.GREEN else Color.RED);
AddChartBubble(IsNaN(close[bm]) and !IsNaN(close[bm1]), LowerBand2[bm1], "LB2", if close[bm1] > LowerBand2[bm1] then Color.GREEN else Color.RED);
AddChartBubble(IsNaN(close[bm]) and !IsNaN(close[bm1]), LowerBand3[bm1], "LB3", if close[bm1] > LowerBand3[bm1] then Color.GREEN else Color.RED);
#
 
Is there a way to get the a price relative to SD . Example price is @ + 1.3 SD
@Goingdar365
That's how it should be working... I have made small changes that suits my trading style. Feel free to use the one that works best for you.

Providing both VWAP and AnchorVWAP in the below.

VWAP

input numDevUp1 = 1.0;
input numDevUP2 = 2.0;
input numDevUP3 = 3.0;
input numDevDn1 = -1.0;
input numDevDn2 = -2.0;
input numDevDn3 = -3.0;
input timeFrame = {default DAY, WEEK, MONTH};

def cap = getAggregationPeriod();
def errorInAggregation =
timeFrame == timeFrame.DAY and cap >= AggregationPeriod.WEEK or
timeFrame == timeFrame.WEEK and cap >= AggregationPeriod.MONTH;
assert(!errorInAggregation, "timeFrame should be not less than current chart aggregation period");

def yyyyMmDd = getYyyyMmDd();
def periodIndx;
switch (timeFrame) {
case DAY:
periodIndx = yyyyMmDd;
case WEEK:
periodIndx = Floor((daysFromDate(first(yyyyMmDd)) + getDayOfWeek(first(yyyyMmDd))) / 7);
case MONTH:
periodIndx = roundDown(yyyyMmDd / 100, 0);
}
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 deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));

plot VWAP = price;
plot UpperBand1 = price + numDevUp1 * deviation;
plot UpperBand2 = price + numDevUp2 * deviation;
plot UpperBand3 = price + numDevUp3 * deviation;
plot LowerBand1 = price + numDevDn1 * deviation;
plot LowerBand2 = price + numDevDn2 * deviation;
plot LowerBand3 = price + numDevDn3 * deviation;

VWAP.setDefaultColor(getColor(0));
UpperBand1.setDefaultColor(getColor(2));
UpperBand2.setDefaultColor(getColor(2));
UpperBand3.setDefaultColor(getColor(2));
LowerBand1.setDefaultColor(getColor(4));
LowerBand2.setDefaultColor(getColor(4));
LowerBand3.setDefaultColor(getColor(4));

input labels = yes;

AddLabel(labels, " ", Color.BLACK);

AddLabel(labels, (if close > LowerBand3 then "[-3]" else "[-3]") + " " + AsText(LowerBand3), if close < LowerBand3 then Color.CYAN else Color.GRAY );

AddLabel(labels, (if close > LowerBand2 then "[-2]" else "[-2]") + " " + AsText(LowerBand2), if close < LowerBand2 then Color.CYAN else Color.LIGHT_GRAY);

AddLabel(labels, (if close > LowerBand1 then "[-1]" else "[-1]") + " " + AsText(LowerBand1), if close < LowerBand1 then Color.CYAN else Color.WHITE);

#AddLabel(labels, " ", Color.BLACK);

AddLabel(labels, (if close > VWAP then "[VWAP]" else "[-VWAP]") + " " + AsText(VWAP), if close > VWAP then Color.GREEN else Color.RED);

#AddLabel(labels, " ", Color.BLACK);

AddLabel(labels, (if close > UpperBand1 then "[1]" else "[1]") + " " + AsText(UpperBand1), if close > UpperBand1 then Color.CYAN else Color.WHITE);

AddLabel(labels, (if close > UpperBand2 then "[2]" else "[2]") + " " + AsText(UpperBand2), if close > UpperBand2 then Color.CYAN else Color.LIGHT_GRAY);

AddLabel(labels, (if close > UpperBand3 then "[3]" else "[3]") + " " + AsText(UpperBand3), if close > UpperBand3 then Color.CYAN else Color.GRAY);

AddLabel(labels, " ", Color.BLACK);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
564 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