VWAP down by X% X periods ago


Category:
0
0

Hi Pete,

I am looking for a scanner to produce results where the VWAP is declining and is down by a percentage which is set by a defined input with the value of say 2%.

I thought this would work but it’s producing undesired results.

# VWAP trending down

input length = 20;
# VWAP down by 2 percent
input percent = 2;

def vwapTrendingDown = vwap < vwap[length];
def lowerVWAPByPercent = vwap/vwap[length] -1 < 1-percent;

plot scan = vwapTrendingDown and lowerVWAPByPercent;

Please know I am using this in a 5 minute aggregation period.
Any help on how to achieve the desired results and making this more efficient will be greatly appreciated.

Thank you

Marked as spam
Posted by (Questions: 7, Answers: 13)
Asked on June 25, 2020 4:30 pm
104 views
0
Private answer

There is a massive difference between the fundamental data type named "vwap"

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

and the built-in chart study named "VWAP"

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

So if you are building your scan using the fundamental data type of "vwap" while plotting the built-in chart study named "VWAP" on your chart. Well you will never get results from the scan that match what you see on the chart.

If that is the case then you need to at least reference the built-in chart study named VWAP in your code. You do this in the following manner:

def myVWAP = reference VWAP()."VWAP";

 

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on June 25, 2020 5:51 pm
0
Thanks for steering me in the direction. def myVWAP = reference VWAP()."VWAP"; It appears I am seeing the desired results but more back-testing is required. Would you mind breaking down the math on in line: def lowerVWAPByPercent and why the input percent is equal to 2% using 0.2 instead of 2? One of the results that appeared on my scanner, with this code, is UBER in the 5 minute time frame. As of 6/28/2020, the VWAP at eod is valued at $29.67 and 20 periods ago the VWAP is valued at $29.72. Would the math workout to being something like: 29.67/29.72 = 0.998317 - 1 = -0.00168237 < 1 - 0.2 = 0.8 so it would return true. But is this is how I'm supposed to understand that line? I did not create that line, it was given to me on an online chat. What I am look to do is enter a value for `input percent = 2%` that would return true if the difference from the current VWAP was 2% from the VWAP 20 periods ago.
( at June 28, 2020 6:48 pm)
0

def lowerVWAPByPercent = vwap/vwap[length] -1 < 1-percent

This line will compute a 2% value as 0.02 and not as 2.0. So the input named "percent" would then need to be converted the decimal equivalent in order to get this to work the way you expect. The way we do this is to multiply the percent input by 0.01 to move the decimal point two places to the left. So that the input value of 2.0 becomes 0.02. So you would modify that line as follows:

def lowerVWAPByPercent = vwap / vwap[length] -1 < 1 - percent * 0.01;

( at June 28, 2020 7:33 pm)
0
Pete, thank you so much for clarifying.
( at July 1, 2020 9:01 am)