Low Above VWAP All Day


Category:
0
0

Pete,

Is it possible to create a scan that yields results for all stocks that have held their lows above VWAP all day? In this scenario, I would be looking to buy a VWAP bounce if the low eventually tests the VWAP.

RESOLVED
Marked as spam
Posted by (Questions: 4, Answers: 1)
Asked on May 1, 2021 8:18 am
186 views
0
Private answer

I can write the code for this however it will not work as you expected.

Here is the code:

def vwapValue = reference VWAP()."VWAP";
def newDay = GetDay() <> GetDay()[1];
rec condition = if newDay then 0 else if low < vwapValue then 1 else condition[1];
plot scan = !condition;

Screenshot below explains why this will not work. Seems that each time a new trading session begins the VWAP value begins right in the middle of the candle. So the very first two bars of each trading session are going to automatically block your signal nearly every single time. That's just the nature of the VWAP study.

In order to get this to work you need to add more conditions to allow time for the VWAP to diverge away from the price action before beginning to check if the low is above the VWAP value.

The following code adds a user input and a bar counter that resets each time a new session begins. The code will ignore the first series of bars as defined by the user input named "barsToIgnore":

input barsToIgnore = 3;
def vwapValue = reference VWAP()."VWAP";
def newDay = GetDay() <> GetDay()[1];
rec countSessionBars = if newDay then 1 else countSessionBars[1] + 1;
rec condition = if newDay then 0 else if countSessionBars >= barsToIgnore and low < vwapValue then 1 else condition[1]; plot scan = !condition and countSessionBars >= barsToIgnore;

The second screenshot below shows the result of the updated code. Very strange to see that recursive variables are not triggering an error in the Study Alert. Those have not been supported previously. I wonder if Thinkorswim developers found a way to correct that limitation. Topic for another post...

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4084)
Answered on May 1, 2021 11:12 am