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

@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);
AnchorVWAP (Please note. The label for this indicator works only between the anchorbegin and anchorEnd setting).

def anchorbegin = 0930;
def anchorEnd = 1630;

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

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

def volumeSum2 = if ShowTodayOnly and !Today
then Double.NaN
else if rth
then volumeSum2[1] + volume
else 0;
def volumeVwapSum2 = if ShowTodayOnly and !Today
then Double.NaN
else if rth
then volumeVwapSum2[1] + volume * vwap
else 0;
def volumeVwap2Sum2 = if ShowTodayOnly and !Today
then Double.NaN
else if rth
then volumeVwap2Sum2[1] + volume * Sqr(vwap)
else 0;
def price2 = volumeVwapSum2 / volumeSum2;
def deviation2 = Sqrt(Max(volumeVwap2Sum2 / volumeSum2 - Sqr(price2), 0));

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

input numDevU1 = 1.0;
input numDevU2 = 2.0;
input numDevU3 = 3.0;
input numDevD1 = -1.0;
input numDevD2 = -2.0;
input numDevD3 = -3.0;

plot UpperLine1 = anchorVWAP + numDevU1 * deviation2;
plot UpperLine2 = anchorVWAP + numDevU2 * deviation2;
plot UpperLine3 = anchorVWAP + numDevU3 * deviation2;

plot LowerLine1 = anchorVWAP + numDevD1 * deviation2;
plot LowerLine2 = anchorVWAP + numDevD2 * deviation2;
plot LowerLine3 = anchorVWAP + numDevD3 * deviation2;

input labelsD = yes;

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

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

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

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

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

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

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

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

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

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

AddLabel(labelsD, " ", Color.BLACK);
 
@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);
wow this is great but i was looking for a watchlist colum
i dont have this study found a picture of it
 
Last edited:
wow this is great but i was looking for a watchlist colum
i dont have this study found a picture of it

Try this in a watchlist set to an intraday timeframe

Capture.jpg
Ruby:
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));
input label = yes;
Addlabel(label , round((close - price) / deviation ,1),
               if close > price
               then Color.GREEN
               else Color.RED );
 
This may give you some ideas. The image is GME 3D 3min chart. Various timeframes have significantly different profit and loss.
Hi SleepyZ, thks for posting the startegy. I copied it and paste but I am not getting anything on the chart. Any thoughts what I could be doing wrong? thanks for your help.
 
Hi SleepyZ, thks for posting the startegy. I copied it and paste but I am not getting anything on the chart. Any thoughts what I could be doing wrong? thanks for your help.

Yes, you are likely copying and pasting the code into a new STUDY. Try creating using the new STRATEGY tab. Here is a shre link with it as a strategy. http://tos.mx/fBm5S2H
 
I am new to thinkscript and having a hard time writing my script.

I want to run a scan that looks for the close price to be above the 9 EMA/20 EMA but below the VWAP. The 9 EMA/20 EMA need to be below VWAP but the 9 needs to be above the 20 . Also the 9 needs to be 5% or less below the VWAP. If I was to be looking at the chart it would all be 1 minute time frame. If you could please let me know if this is even worth the time to make or use.

Thanks
 
Last edited:
I am new to thinkscript and having a hard time writing my script.

I want to run a scan that looks for the close price to be above the 9 EMA/20 EMA but below the VWAP. Then the 9 EMA/20 EMA need to be below VWAP but the 9 needs to be above the 20. Also the 9 needs to be 5% or less below the VWAP. If I was to be looking at the chart it would all be 1 minute time frame. If you could please let me know if this is even worth the time to make or use.

can you edit your post #1 and clarify a few things.

i understand your 1st sentence,
close to be above the 9 EMA/20 EMA but below the VWAP.

condition1 =
close > EMA9 and
close > EMA20 and
close < VWAP


but i don't understand this. what do you mean by 'then'?
does this need to happen , 1 bar, or 4 bars, or 22 bars, or any bars?? after the first condition happens ?

Then the 9 EMA/20 EMA need to be below VWAP but the 9 needs to be above the 20.
Also the 9 needs to be 5% or less below the VWAP.

condition2 =
EMA9 > EMA20 and
EMA20 < VWAP and
EMA9 < VWAP and
EMA9 > VWAP * 0.95
 
can you edit your post #1 and clarify a few things.

i understand your 1st sentence,
close to be above the 9 EMA/20 EMA but below the VWAP.

condition1 =
close > EMA9 and
close > EMA20 and
close < VWAP


but i don't understand this. what do you mean by 'then'?
does this need to happen , 1 bar, or 4 bars, or 22 bars, or any bars?? after the first condition happens ?

Then the 9 EMA/20 EMA need to be below VWAP but the 9 needs to be above the 20.
Also the 9 needs to be 5% or less below the VWAP.

condition2 =
EMA9 > EMA20 and
EMA20 < VWAP and
EMA9 < VWAP and
EMA9 > VWAP * 0.95
"but i don't understand this. what do you mean by 'then'?
does this need to happen , 1 bar, or 4 bars, or 22 bars, or any bars?? after the first condition happens ?"

The best thing I can say is would it be possible to get the code for having a bar requirement and not having a bar requirement. Now that you asked this I really don't have a answer because I was not thinking about a lag between them. As I said in the original post I am not even sure if this is even worth it.
 
Has anyone tried to write a search for the DAILY VWAP crossing above the MONTHLY VWAP? I put the two VWAPs on a chart by accident and it seemed to be a great indicator on a 15 min chart !!
When I try to write, the script won't let me mix the daily and monthly together. No secondary time frame.
Can any one help? Looking for a search script for the daily vwap crossing above the monthly.
Thank you
 
Has anyone tried to write a search for the DAILY VWAP crossing above the MONTHLY VWAP? I put the two VWAPs on a chart by accident and it seemed to be a great indicator on a 15 min chart !!
When I try to write, the script won't let me mix the daily and monthly together. No secondary time frame.
Can any one help? Looking for a search script for the daily vwap crossing above the monthly.
Thank you

See if this helps There are arrows where the day and week cross on a 15m chart below.

Capture.jpg

Ruby:
plot dvwap = reference VWAP();
plot wvwap = reference VWAP("time frame" = "WEEK");
plot arrowup = if dvwap crosses above wvwap then 1 else 0;
arrowup.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
arrowup.SetLineWeight(3);
arrowup.SetDefaultColor(Color.CYAN);
plot arrowdn = if dvwap crosses below wvwap then 1 else 0;
arrowdn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
arrowdn.SetLineWeight(3);
arrowdn.SetDefaultColor(Color.YELLOW);
 
Has anyone tried to write a search for the DAILY VWAP crossing above the MONTHLY VWAP?
Looking for a search script for the daily vwap crossing above the monthly.
The ToS platform does not support secondary aggregation use in the Scan Hacker.
 
Hello I am new and no experience with code. I am trying to find an alert for when the VWAP crossover the 9 EMA.
 
Hello I am new and no experience with code. I am trying to find an alert for when the VWAP crossover the 9 EMA.

Put this in a new study on a chart

Code:
input hideplots = no;
plot vwap = reference vwap();
plot ema9 = expaverage(close, 9);
vwap.sethiding(hideplots);
ema9.sethiding(hideplots);
def cross = ema9 crosses vwap;
alert(cross, if ema9 crosses above vwap then "OVER" else "UNDER", alert.bar, sound.Ding);
 
Thankk you, I do have this on my chart and it works great, but I want to know if there was a way to be
notified/alert when the VWAP crossover the 9EMA
 
Thankk you, I do have this on my chart and it works great, but I want to know if there was a way to be
notified/alert when the VWAP crossover the 9EMA
Sure just flip the code around. There will be a mesage center notification and sound alert

Code:
input hideplots = no;
plot vwap = reference vwap();
plot ema9 = expaverage(close, 9);
vwap.sethiding(hideplots);
ema9.sethiding(hideplots);
def cross = vwap crosses ema9;
alert(cross, if vwap crosses above ema9 then "OVER" else "UNDER", alert.bar, sound.Ding);
 
Hi Family,
I need help on scripting an upper label indicator that whenever I type in the ticker would tell me how much in dollars and percentage it's trading above or below the vwap in real time. Ideally that would work in whatever intraday timeframe I'm looking at.
Can someone please help me?
I greatly appreciated!
Thanks,
Will
 
Last edited:
Hi Family,
I need help on scripting an upper label indicator that whenever I type in the ticker would tell me how much in dollars and percentage it's trading above or below the vwap in real time. Ideally that would work in whatever intraday timeframe I'm looking at.
Can someone please help me?
I greatly appreciated!
Thanks,
Will

Try this

Code:
def v = reference VWAP();
def vpercent = (close - v) / v;

AddLabel(1, "VWAP Diff || " + AsDollars(close - v) + "|| %: " + AsPercent(vpercent), if close > v then Color.GREEN else Color.RED);

#addlabel(1,close + " " + v);
 
It seems to be working. Thank YOU so much!!!
How about from the 50EMA on intraday and per example 5EMA on the daily? Is that also possible to do?
Thank YOU so much!
 
Last edited:
It seems to be working. Thank YOU so much!!!
How about from the 50EMA on intraday and per example 5EMA on the daily? Is that also possible to do?
Thank YOU so much!

Sure, here you go

Ruby:
def v = reference VWAP();
def vpercent = (close - v) / v;

AddLabel(1, "VWAP Diff || " + AsDollars(close - v) + "|| %: " + AsPercent(vpercent), if close > v then Color.GREEN else Color.RED);

#addlabel(1,close + " " + v);

def ema5  = ExpAverage(close, 5);
def ema50 = ExpAverage(close, 50);

def ema5percent = (close - ema5) / ema5;
AddLabel(GetAggregationPeriod() < AggregationPeriod.DAY, "EMA5 Diff || " + AsDollars(close - ema5) + "|| %: " + AsPercent(ema5percent), if close > ema5 then Color.GREEN else Color.RED);

def ema50percent = (close - ema50) / ema50;
AddLabel(GetAggregationPeriod() >= AggregationPeriod.DAY, "EMA50 Diff || " + AsDollars(close - ema50) + "|| %: " + AsPercent(ema50percent), if close > ema50 then Color.GREEN else Color.RED);
 
does TOS have a ticker showing % of stocks within SP500 or nasdaq 100 above vwap?

or is it possible to make such an indicator?
 

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
359 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