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

@Jimmy Here is your COMBINED label to display as a chart label. Note that because you are displaying multiple pieces of info, you won't be able to contain all this in a single watchlist UNLESS you simplify the display. This should give you some ideas how to best structure what you'd eventually like to implement

Code:
# Distance from SMA and VWAP
# tomsk
# 12.12.2019

input length = 9;

def sma = Average(close, length);
def DistanceSMA = (close - sma);
def vwapValue = VWAP();
def DistanceVWAP = (close - vwapValue);

AddLabel(1, "Distance SMA(" + length + ") = " + AsText(DistanceSMA) + " (" + AsPercent(close/sma-1) + ") " + "VWAP = " + AsText(DistanceVWAP) + " (" + AsPercent(close/vwapValue-1) + ")", 
    if close > sma and close > vwapValue then Color.GREEN else if close < sma and close < vwapValue then Color.RED else if close < sma and close > vwapValue then Color.YELLOW else if close 

> sma and close < vwapValue then Color.ORANGE else Color.WHITE);
# End Distance from SMA and VWAP
 
@tomsk Thank you,

I've been working on this for a while, you're right there's a lot of info for a column... probably just go with leaving the price distance off the column and just go with the conditions...if price above both sma and VWAP color green and so on.

Again thank you for your time and insight. Much appreciated
 
Simplification is the key. The watchlists already have very limited real estate to display info, what you're suggesting can be challenging.
If you really must have the info on your watchlist, then you may consider separate watchlist columns
A third alternative is just to color code your watchlist and dispense with the other info like distance, percentage, etc
Keep it simple
 
Yes, you are right.
Your only allowed so much data per list..(1500 I believe) unless you pay for extra data. So it would only be able to handle a couple of stocks.
I would like to add distance from 9 to VWAP to the label as well.. working on it now.
I can't thank you enough for this script.
I scalp trade during the day from the average price line(which is basically the 9) to VWAP and this gives me a really good visual of the actual price move. The percentage distance I will use as a scan once I can determine through logging a consistent range before price re-traces.
Thank you again
 
Yes, you are right.
Your only allowed so much data per list..(1500 I believe) unless you pay for extra data. So it would only be able to handle a couple of stocks.
I would like to add distance from 9 to VWAP to the label as well.. working on it now.
I can't thank you enough for this script.
I scalp trade during the day from the average price line(which is basically the 9) to VWAP and this gives me a really good visual of the actual price move. The percentage distance I will use as a scan once I can determine through logging a consistent range before price re-traces.
Thank you again
Simplification is the key. The watchlists already have very limited real estate to display info, what you're suggesting can be challenging.
If you really must have the info on your watchlist, then you may consider separate watchlist columns
A third alternative is just to color code your watchlist and dispense with the other info like distance, percentage, etc
Keep it simple
For some reason the values are off on my chart... VWAP on the label doesn't match the VWAP line on the chart... Any ideas on what I need to do to fix this
 
For some reason the values are off on my chart... VWAP on the label doesn't match the VWAP line on the chart... Any ideas on what I need to do to fix this


Check your aggregations. Only way to truly debug this is to throw a couple of AddLabel statements in your code to confirm the numbers
Other than that I can't think of anything else
 
Last edited:
For some reason the values are off on my chart... VWAP on the label doesn't match the VWAP line on the chart... Any ideas on what I need to do to fix this
My labels seem to be off by a couple of cents.
Check your aggregations. Other than that I can't think of anything else
I'll give it a run through in the morning.. my VWAP was off by a penny on the futures which it's been off by a couple of cents on stocks. Has to be something with the aggregation because all of my labels are off by a few cents
 
@tomsk
I've been trying to to add distance from the 9 to VWAP to the label and I can't seem to get it right. I'm stumped, if you have time could you write it so I can see where I'm wrong.
Thanks


Distance from the SMA(9) to the VWAP can easily be computed, it's all math.

Code:
input length = 9;

def sma = Average(close, length);
def vwapValue = VWAP();
def distance = sma - vwapValue;
AddLabel(1, "Distance SMA(" + length + ") to VWAP = " + AbsValue(distance), Color.YELLOW);


You can get fancy with this and add bells and whsitles as may be necessary.
 
@tomsk
AddLabel(1, "Distance SMA(" + length + ") = " + AsText(DistanceSMA) + " (" + AsPercent(close/sma-1) + ") " + "VWAP = " + AsText(DistanceVWAP) + " (" + AsPercent(close/vwapValue-1) + ")",

I was trying to add it to the end of this.
I can write scripts to get the distance between price and an moving average but seem to be having trouble between moving average to moving average.
 
@tomsk
AddLabel(1, "Distance SMA(" + length + ") = " + AsText(DistanceSMA) + " (" + AsPercent(close/sma-1) + ") " + "VWAP = " + AsText(DistanceVWAP) + " (" + AsPercent(close/vwapValue-1) + ")",

I was trying to add it to the end of this.
I can write scripts to get the distance between price and an moving average but seem to be having trouble between moving average to moving average.
@tomsk
I was writing and posting as your response came through.
Thank you
 
Let's get real specific shall we? Not sure I understand what you're really looking for

From the above convo, I gather you'll like to modify post #2 and add in that single label statement the distance from SMA(9) to VWAP?
Or did you mean something else? Please be as explicit as you can. When in doubt provide as much detail as possible so there won't be any misunderstandings.

This forum, unlike a typical chatroom may not be the best medium for a two way interactive exchange, so best to be real explicit so we can help you
 
I was up all night trying to create a code which will display the distance amount between my entry price and the 9 ema line on both 5 min chart and 1 minute chart and could not find a way to do that. Any help will be much appreciated..thanks everyone!!!
 
I was up all night trying to create a code which will display the distance amount between my entry price and the 9 ema line on both 5 min chart and 1 minute chart and could not find a way to do that. Any help will be much appreciated..thanks everyone!!!
Is your entry price pre determined or is it real time?
 
Let's get real specific shall we? Not sure I understand what you're really looking for

From the above convo, I gather you'll like to modify post #2 and add in that single label statement the distance from SMA(9) to VWAP?
Or did you mean something else? Please be as explicit as you can. When in doubt provide as much detail as possible so there won't be any misunderstandings.

This forum, unlike a typical chatroom may not be the best medium for a two way interactive exchange, so best to be real explicit so we can help you
@tomsk
Good afternoon,
Yes, you are correct I am going to add this to post #2.
I was wanting one label that shows:
1) distance from price to 9
2) distance from price to VWAP
3) distance from 9 to VWAP
I will use this label for a couple of different things.
1) most important is, I scalp trade from a break of the 9 to VWAP on lower times frames using options. So having a visual of actual price helps me save calculation time.
2) having the percentages added and distances of each one individual, hopefully later( after some extensive logging) I'll be able to create a scan alert that will allow me some time to catch a setup early so that I don't miss a move.
Thank you so much for all your help
Jimmy
 
Last edited:
@Jimmy Here is the modified version to tack on SMA(9) to VWAP per your request.

Code:
# Distance from SMA and VWAP
# tomsk
# 12.15.2019

# Added distance from SMA(9) to VWAP as requested by @Jimmy

input length = 9;

def sma = Average(close, length);
def DistanceSMA = (close - sma);
def vwapValue = VWAP();
def DistanceVWAP = (close - vwapValue);

AddLabel(1, "Price to SMA(" + length + ") = " + AsText(DistanceSMA) + " (" + AsPercent(close/sma-1) + ")" + "    Price to VWAP = " + AsText(DistanceVWAP) + " (" + AsPercent(close/vwapValue-1) + ")" + "    SMA(" + length + ") to VWAP = " + AsText(sma-vwapValue) + " (" + AsPercent(sma/vwapValue-1) + ")", if close > sma and close > vwapValue then Color.GREEN else if close < sma and close < vwapValue then Color.RED else if close < sma and close > vwapValue then Color.YELLOW else if close > sma and close < vwapValue then Color.ORANGE else 
Color.WHITE);
# End Distance from SMA and VWAP
 
Hi! I am trying to get a TOS scanner for EMA(9) crosses VWAP by certain lookback bars (1bar, 2 bars, 3 bars etc) for intraday trading? I am not sure how to change the codes in the watchlist above.; can anybody help ?
 
@Bung Bang A scan code that looks for EMA(9) crossing VWAP can be simply coded as follows. If you want this to lookback 2 bars, just change the value of the variable lookback to 2. Be default it is set to 0, which means it looks at the current bar.

Code:
def lookback = 0;
def EMA = ExpAverage(close, 9);
def vwapValue = VWAP()[lookback];

plot scan = EMA crosses vwapValue;
 
Is there a way to color code watchlist stocks with custom filed based on price Cross over vwap upper band and vwap lower band and vwap?

i saw a post to mark bullish and bearish when price move above and below vwap but i would like to leave rage that to identify vwap upper and lower band cross also with different coloring so that it will be easy for us to watch the stock when it reaches those levels.
 

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