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

Hi,
I am trying to find VWAP at a specific time of the day. Say for example, how to find the VWAP after 30 minutes of opening? I am wondering if this is possible and if so would someone post the code.

Thanks in advance,
Kundurs
 

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

Hi,
I am trying to find VWAP at a specific time of the day. Say for example, how to find the VWAP after 30 minutes of opening? I am wondering if this is possible and if so would someone post the code.

Thanks in advance,
Kundurs

Try the following code... Note that if you change the vwapTime you also need to change it in the AddLabel() text... Also, if you want to use a different time that requires a different AggregationPeriod that you will need to change that as well... Modify to your needs...

Ruby:
# VWAP_At_Time
# Created by rad14733 for usethinkscript.com per @kundurs request
# v1.0 : 2021-07-23 : Initial Release

def vwapTime = 1000;
def vwapVal = if SecondsFromTime(vwapTime) == 0 then vwap(period = AggregationPeriod.THIRTY_MIN) else if SecondsFromTime(vwapTime) > 0 then vwapVal[1] else 0;
AddLabel(yes, "10:00 vwap = " + vwapVal, Color.WHITE);

# END - VWAP_At_Time
 
Many Thanks @Ruby,
Excellent Job!
I made a minor modification (was plotting 0 for the first bar). Here is the modified code:
# VWAP_At_Time
# Created by rad14733 for usethinkscript.com per @kundurs request
# v1.0 : 2021-07-23 : Initial Release

def vwapTime = 1000;
def vwapVal = if SecondsFromTime(vwapTime) == 0 then vwap(period = AggregationPeriod.THIRTY_MIN) else if SecondsFromTime(vwapTime) > 0 then vwapVal[1] else Double.NaN;
AddLabel(yes, "10:00 vwap = " + vwapVal, Color.WHITE);
 
@kundurs In actuality, VWAP remains the same regardless of timeframe, barring extended decimal points, so the following would also work... No need for an AggregationPeriod...

Ruby:
# VWAP_At_Time
# Created by rad14733 for usethinkscript.com per @kundurs request
# v1.0 : 2021-07-23 : Initial Release

def vwapTime = 1000;
def vwapVal = if SecondsFromTime(vwapTime) == 0 then vwap() else if SecondsFromTime(vwapTime) > 0 then vwapVal[1] else Double.NaN;
AddLabel(yes, "10:00 vwap = " + vwapVal, Color.WHITE);
 
I am attempting to set up a watchlist column that would visually show if the stock has stacked VWAPs (Weekly VWAP greater or equal to Monthly VWAP). For some reason, all I am getting is a "loading". Any input would help!

Here is what I have so far:

plot VWAPW = VWAP(period = AggregationPeriod.WEEK);
plot VWAPM = VWAP(period = AggregationPeriod.MONTH);

def bullish = VWAPW is greater than or equal to VWAPM;
def bearish = VWAPW is less than VWAPM;

AddLabel(bullish, “Bullish VWAP⇧”, color.black);
AddLabel(bearish, “Bearish VWAP⇩”, color.black);
AddLabel(!bullish and !bearish, " ", color.black);

AssignBackgroundColor (if bullish then color.green else if bearish then color.red else color.black);
 
@PapaBear10 Your code had several syntax errors. Here is my version of a VWAP Watchlist that is painted green when 9 ema crosses above vwap within last 3 bars. It is painted red when 9 ema crosses below vwap within last 3 bars. Remember to select the aggregation period you are interested in when configuring this watchlist

Code:
# VWAP Watchlist
# tomsk
# 1.25.2020

# Watchlist that is painted green when 9 ema crosses above vwap within last 3 bars
# It is painted red when 9 ema crosses below vwap within last 3 bars

input length = 9;

def ema = ExpAverage(close, length);
def vwapValue = reference VWAP();
def crossUp = ema crosses above vwapValue within 3 bars;
def crossDn = ema crosses below vwapValue within 3 bars;
AddLabel(1, if crossUp then "X Up" else if crossDn then "X Down" else " ", Color.Black);
AssignBackgroundColor(if ema crosses above vwapValue then Color.GREEN
                      else if ema crosses below vwapValue then Color.RED
                      else Color.Gray);
# End VWAP Watchlist
Trying to set up your watchlist, but it does not appear as a watchlist item that I can add, and when I enter it manually as a custom watchlist item, TOS won't let me click save. How can I put your watchlist in action?
 
Another Way To Load Watch Lists
Shared Link: http://tos.mx/8PcaOer
Click here for --> Easiest way to load shared links
EPifVeZ.png

@Batman
 
Last edited:
Hi all,

I searched and couldn’t find something, sorry if I missed it (please post link if I did miss it).

I’m looking to add both 9 and 21 EMA crossover VWAP.

So basically 4 indicators on 1 min chart;
  • 9 EMA crossover VWAP on 5 min
  • 9 EMA crossover VWAP on 15 min
  • 21 EMA crossover VWAP on 5 min
  • 21 EMA crossover VWAP on 15 min

is that possible?

thanks in advance

Hopefully with the following you can adjust it to your liking. It only uses the reference vwap set to daily for eace of the crosses, showing as green if above and red if below

Screenshot-2021-08-13-144529.jpg
Ruby:
input showlabels = yes;
input showplots  = yes;
input agg1 = AggregationPeriod.FIVE_MIN;
input agg2 = AggregationPeriod.FIFTEEN_MIN;
input len1 = 9;
input len2 = 21;
plot vwap  = reference VWAP();
plot ema1  = ExpAverage(close(period = agg1), len1);
plot ema2  = ExpAverage(close(period = agg2), len1);
plot ema3  = ExpAverage(close(period = agg1), len2);
plot ema4  = ExpAverage(close(period = agg2), len2);
ema1.SetHiding(!showplots);
ema2.SetHiding(!showplots);
ema3.SetHiding(!showplots);
ema4.SetHiding(!showplots);
ema1.AssignValueColor(if ema1 > vwap then Color.GREEN else Color.RED);
ema2.AssignValueColor(if ema2 > vwap then Color.GREEN else Color.RED);
ema3.AssignValueColor(if ema3 > vwap then Color.GREEN else Color.RED);
ema4.AssignValueColor(if ema4 > vwap then Color.GREEN else Color.RED);
AddLabel(showlabels, "EMA9 " +  agg1 / 60000 + "m", if ema1 > vwap then Color.GREEN else Color.RED);
AddLabel(showlabels, "EMA21 " +  agg1 / 60000 + "m", if ema3 > vwap then Color.GREEN else Color.RED);
AddLabel(showlabels, "EMA9 " +  agg2 / 60000 + "m", if ema2 > vwap then Color.GREEN else Color.RED);
AddLabel(showlabels, "EMA21 " +  agg2 / 60000 + "m", if ema4 > vwap then Color.GREEN else Color.RED);
 
Another Way To Load Watch Lists
Shared Link: http://tos.mx/8PcaOer
Click here for --> Easiest way to load shared links
EPifVeZ.png

@Batman[/UF
[/QUOTE]

Another Way To Load Watch Lists
Shared Link: http://tos.mx/8PcaOer
Click here for --> Easiest way to load shared links
EPifVeZ.png

@Batman
First time caller long time listener.... I appreciate what all you guys do here. I was looking around for this but haven't found exactly what i wanted. Basically what i want is to add to my watchlist something like the above photo but I want it to ... show price close is above or equal to VWAP and above the 200SMA (when it is i want it to paint green) and also to show price close is below VWAP and VWAP is below 200SMA (when this happens paint Red) (if none of the above black)

I'm not very good at these scripts and the below is what i was trying to do but it's not correct. Any help greatly appreciated.

def VWAP = close crosses above reference VWAP ()."VWAP";

def SMA200 = close is greater than or equal to SimpleMovingAvg()."SMA" from 200 bars ago;

def BullStack = close is greater than VWAP and VWAP is greater than or equal to SMA200;

def BearStack = close is less than VWAP and VWAP is less than or equal to SMA200;



AddLabel(BullStack, “Bull”, color.green);

AddLabel(BearStack, “Bear”, color.red);

AddLabel(!BullStack and !BearStack, "Do Nothing", color.BLACK);
 
First time caller long time listener.... I appreciate what all you guys do here. I was looking around for this but haven't found exactly what i wanted. Basically what i want is to add to my watchlist something like the above photo but I want it to ... show price close is above or equal to VWAP and above the 200SMA (when it is i want it to paint green) and also to show price close is below VWAP and VWAP is below 200SMA (when this happens paint Red) (if none of the above black)

I'm not very good at these scripts and the below is what i was trying to do but it's not correct. Any help greatly appreciated.

def VWAP = close crosses above reference VWAP ()."VWAP";

def SMA200 = close is greater than or equal to SimpleMovingAvg()."SMA" from 200 bars ago;

def BullStack = close is greater than VWAP and VWAP is greater than or equal to SMA200;

def BearStack = close is less than VWAP and VWAP is less than or equal to SMA200;



AddLabel(BullStack, “Bull”, color.green);

AddLabel(BearStack, “Bear”, color.red);

AddLabel(!BullStack and !BearStack, "Do Nothing", color.BLACK);

Code:
# hello, i see a couple of things you can try changing.  the main problem is that you are comparing numbers to boolean values( true/false).
# vwap and sma200 are true/ false values. in your bull and bear formulas,  you comparing them as if they are numbers.

# try to use unique variable names. change vwap.  use a variable to hold the wvap value.
def vwap1 = reference VWAP()."VWAP";

# this isn't used
#def VWAPxup = close crosses above reference VWAP()."VWAP";

# if you want a 200 period average, put the number between the ( ).
# what you are referencing is a study. there are also functions that you can use, to get average values.
# it is ok to combine functions in a long formula, but sometimes it is easier to fix if you separate things out into several formulas.
# i would define a variable to hold the vwap and average values, then use a 2nd variable to compare it to something.
def SMA200 = SimpleMovingAvg( length = 200 )."SMA";

# this isn't neeed
#def abovesma = (close >= sma200);

def BullStack = close > VWAP1 and VWAP1 >= SMA200;

def BearStack = close < VWAP1 and VWAP1 <= SMA200;

AddLabel(BullStack, “Bull”, color.green);

AddLabel(BearStack, “Bear”, color.red);

AddLabel(!BullStack and !BearStack, "Do Nothing", color.BLACK);

# combined label
AddLabel( BullStack or bearstack,
(if BullStack then "Bull" else if bearstack then "Bear" else "----"),
(if BullStack then color.green
else if bearstack then color.red else color.black) );
# there are only 2 conditions that trigger the label. so if it is not a bull or bear, no label will appear. 
# because i used 2 definite conditions , i had to finish with a 3rd to complete the if-thens. (  ----  and black)

this is a study to calculate an average. you can reference it or load it in your study set and it will draw lines.
https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/R-S/SimpleMovingAvg

there are also functions to calculate averages. they don't draw lines, they just calculate a number.
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/MovingAverage
 
I made this to show it as a %.
How can I make the font black?
And round to 1 decimal place?

plot vwap = (close-vwap())/close*100;
AssignBackgroundColor(if vwap > 0 then Color.GREEN else if vwap < 0 then Color.RED else Color.BLACK);
 
@geebeeaye Added round function and by default the font is black:
Ruby:
def calc_vwap = (close-vwap())/close*100;
plot vwap = round(calc_vwap,1);
AssignBackgroundColor(if vwap > 0 then Color.GREEN else if vwap < 0 then Color.RED else Color.BLACK);
Screenshot (27).png
 
@geebeeaye In dark mode the font is white. There is technically no changing that.
But.... If we change the element to a label then there are more editing options.
Here it is as a label w/ black text...
Ruby:
def calc_vwap = (close-vwap())/close*100;
def vwap = round(calc_vwap,1);
AddLabel(yes, vwap, color.black);
AssignBackgroundColor(if vwap > 0 then Color.GREEN else if vwap < 0 then Color.RED else Color.BLACK);
Screenshot (27).png
 
Last edited:
@Britt95 You can paint the Chart background using AssignBackgroundColor()... Note, this colors the background rather than painting a cloud...

Ruby:
AssignBackgroundColor(if close > vwap then Color.GREEN else if close < vwap then Color.RED else Color.CURRENT);
 
I've been trying to figure out how to code this for intraday but am having a very difficult time doing so. All the scripts I've found never worked for intraday (1m/5m) charts.
I would use this one but it doesn't seem to work for intraday

plot vwap = vwap();
AssignBackgroundColor(if close > vwap then Color.DARK_GREEN else if close < vwap then Color.DARK_RED else Color.Dark_ORANGE);

It shows colors and for some tickers it is accurate but many of them aren't so I'm guessing it's deriving the VWAP from a different time frame. I'm trying to show in the Watchlist whether a ticker is above or below the VWAP at the current price, possibly within 5 bars on the 1 minute time frame?

I'm also trying to figure out how to show when a ticker is above or below the zero line on the RSMK, again intraday and on the Watchlist. I've found a code that would compare the stock to multiple tickers like SPY/QQQ/VOO but I'm just trying to compare it to SPY.

Is there anyone that has a code for that or can possibly figure it out?
 
I've been trying to figure out how to code this for intraday but am having a very difficult time doing so. All the scripts I've found never worked for intraday (1m/5m) charts.
I would use this one but it doesn't seem to work for intraday

plot vwap = vwap();
AssignBackgroundColor(if close > vwap then Color.DARK_GREEN else if close < vwap then Color.DARK_RED else Color.Dark_ORANGE);

It shows colors and for some tickers it is accurate but many of them aren't so I'm guessing it's deriving the VWAP from a different time frame. I'm trying to show in the Watchlist whether a ticker is above or below the VWAP at the current price, possibly within 5 bars on the 1 minute time frame?

I'm also trying to figure out how to show when a ticker is above or below the zero line on the RSMK, again intraday and on the Watchlist. I've found a code that would compare the stock to multiple tickers like SPY/QQQ/VOO but I'm just trying to compare it to SPY.

Is there anyone that has a code for that or can possibly figure it out?

In the following code snippets, included is assignbackground color code that is commented (inactive) out. If you want to use these in a watchlist column, then comment out the assignvalue and setlineweight code and uncomment the assignbackground color code.

Vwap is both a price and indicator. To use it as an indicator you use, reference vwap().
Ruby:
plot v = reference vwap();
v.assignValueColor(if close > v then Color.DARK_GREEN else if close < v then Color.DARK_RED else Color.Dark_ORANGE);
v.setlineWeight(5);
#assignbackgroundColor(if close > v then Color.DARK_GREEN else if close < v then Color.DARK_RED else Color.Dark_ORANGE);

RSMK has periods where it does not plot for whatever reason, so you have to use the prior bars RSMK in those instances in the code.
Ruby:
def r = if IsNaN(reference RSMK()) then r[1] else reference RSMK();
plot rsmk = r;
rsmk.AssignValueColor(if r >= 0 then Color.GREEN else Color.RED);
rsmk.SetLineWeight(5);
#assignbackgroundColor(if r>=0 then color.green else color.red);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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