VWAP in a custom Scan filter not returning TRUE

jrandydavis

New member
Plus
Hello-- I've written a custom scan filter that includes the VWAP value, but something must not be correct, as the results (and corresponding scan Alerts) do not match the VWAP criterion in the filter. Everything else on the scanner seems to return TRUE. For example, on a 5 min Agg + EXT, I have in a custom scan filter-- open[1] > average(open, 7)[10] AND volume[1] > 150000 AND close[1] > VWAP()[1]. The filter and Alerts return results that are TRUE for the open[1] and volume[1] equations, but not for the VWAP equation (i.e. shows results where the close from the previous bar is both higher and lower that the VWAP value at that bar). I'm not sure what I'm doing wrong here, any help or insight would be much appreciated. First post here-- let me know if any add'l info is needed.
JRD
 
Most likely, it's using the VWAP fundamental, rather than referencing the VWAP study. You can check this easily. If "VWAP" is turning green in the editor, it's wrong.

def x = reference vwap;
.... and close[1] > x[1]
 

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

Most likely, it's using the VWAP fundamental, rather than referencing the VWAP study. You can check this easily. If "VWAP" is turning green in the editor, it's wrong.

def x = reference vwap;
.... and close[1] > x[1]
Thank you Joshua for the response. As per your reply, I tried--

def x = reference vwap;
close[1] > x[1]

as 2 separate lines of code, both in a custom scan filter, and in a (chart) custom study. TS Editor didn't like the second line in either instance.

Can you tell me more about the VWAP fundamental vs VWAP study data, or where to find more practical (i.e. scan filter-related) info on it? I did read the the ToS Tutorial on VWAP, and did not see mention of the difference. I thought this would be a straightforward data grab, but it's been a headache for a week now with no resolution in sight.
I'm just hoping to find the best/most accurate way to compare the VWAP value to the other $ values on a given chart (open, close, etc.) for use in a scan filter. Even when I make an entry, the Condition Wizard seems to like it format-wise, but clearly I'm not communicating thru code properly to call out the VWAP data/value that I'd like. Thanks for any other insight.
JRD
 
I am a bit rusty, my only experience with VWAP is helping people here. I don't use it myself. Anyway, the formula for VWAP has an input known as "typical price." In every other platform that I know of, as well as every website that hosts the VWAP formula, I recall that the typical price is always HLC3.

TOS, on the other hand, has a VWAP fundamental. This is more akin to other basic price points like Open, Volume, High, Tick Count, and so forth. TOS uses this VWAP fundamental inside of its actual VWAP study in place of HLC3.

https://toslc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/V-Z/VWAP

https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Fundamentals/vwap
 
I am a bit rusty, my only experience with VWAP is helping people here. I don't use it myself. Anyway, the formula for VWAP has an input known as "typical price." In every other platform that I know of, as well as every website that hosts the VWAP formula, I recall that the typical price is always HLC3.

TOS, on the other hand, has a VWAP fundamental. This is more akin to other basic price points like Open, Volume, High, Tick Count, and so forth. TOS uses this VWAP fundamental inside of its actual VWAP study in place of HLC3.

https://toslc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/V-Z/VWAP

https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Fundamentals/vwap


Thank you Joshua for your response. I realized from your last answer that I did not know enough to even ask the right questions, so I spent this time learning more about the VWAP and how to implement it. I've made some progress I think, and now have some more specific and hopefully relevant questions.

As to your comment about plotting the reference VWAP, the resulting plot was a flat line at 0 on my charts, with occasional "bumps" which turned out to be 1. So it was a 1 or 0 situation, which I think explains why my original attempts produced results where (nearly) every stock price was > than the VWAP.

So I now have a study that I've put together from a couple of sources for a (daily) anchored VWAP. The code is as follows:
Code:
Input Year = 2026;

Input Month = 01;

Input Day = 01;

input AnchorTime = 0130;

def AnchorDate = (Year * 10000)+(Month * 100)+Day;

def postAnchorDate = if getYYYYMMDD() >= AnchorDate then 1 else 0;

def postAnchorTime = if secondsFromTime(AnchorTime) >=0 then 1 else 0;

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.Medium_Dash);

anchoredVWAP.setDefaultColor(color.orange);

This produces a VWAP plot that closely follows the default ToS version, but uses, as you pointed out previously, the more common HLC3 data. Testing is early and preliminary, but it seems to work when for instance in a scanner I have the equation: close[1] > MyAnchoredVWAP()[1] [[ = the name of the custom study]], it returns stocks on the 5min agg that closed above the VWAP plot on the previous bar only.

I plan to test it "live" this week, but there is still a small wrinkle that is concerning. Currently, some of my Watchlist Scanners use the exact formula above-- close[1] > MyAnchoredVWAP()[1] in a custom Study filter. Whenever I enter this formula or edit it in ThinkScript, once I hit OK, I get the following warning message:

'This filter is linked to the custom script:
MyAnchoredVWAP
If you make changes to any linked script those changes WILL NOT be reflected in this filter.'

While I understand the meaning of this sentence in general (I think), I'm not sure what this means on a practical level. What kinds of specific changes are they referring to? How would one "reset" the situation once any necessary changes were made to the study script??

One specific concern would be the adjustment to the anchor time, which I'd have to set or 'change' every morning/evening prior to reflect the correct day/date. I'm not sure if this would influence the results from my relevant watchlist scanners each day, or how to overcome the issue if it in fact does. Are you familiar with this specific warning message, and can you offer any insight on ways to work around whatever limitations/restrictions that are implied? Any other comments/suggestions are welcomed as well.
Thank you again,
JRD
 
Last edited by a moderator:
Editing a script within a scan doesn't affect pre-existing scans unless you save the scan again. It might take it a few moments to kick in though. Sometimes, after the re-save, it helps to switch the watch list to another list and back again, or just outright delete it and re-save when its being particularly laggy.
 
@jrandydavis

ToS is correct:
If you make changes to any linked script those changes WILL NOT be reflected in this filter.

And @Joshua workarounds are a good idea.

But it you want to ensure that it is working with your current script.
Just always create a new scan each morning.
Otherwise; it sometimes switches back to the old script until the servers update; which sometimes doesn't happen until overnight.
 
Editing a script within a scan doesn't affect pre-existing scans unless you save the scan again. It might take it a few moments to kick in though. Sometimes, after the re-save, it helps to switch the watch list to another list and back again, or just outright delete it and re-save when its being particularly laggy.
Thanks for your post. You really helped me
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
488 Online
Create Post

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