VWAP scan first bar crossing below and second crossing above



I want to scan and alert when the following conditions occur.  The timeframe does not matter 15 min, 30 min, etc:

First candle opens above VWAP and closes below VWAP

Second candle opens below VWAP and closes above VWAP

Please see attached screenshot.  I have not been able to figure out how to reference the 1st, 2nd, and 3rd candles of the day.  Thanks in advance!

Marked as spam
Posted by (Questions: 1, Answers: 0)
Asked on December 11, 2018 1:24 pm
Pete, Is there a way I can test what symbols would have shown up today 6/24/19 with the below code with two additional criteria now that the trading day is over? I would be scanning in All Nasdaq Stocks. Last minimum $12 Vol minumum 300,000
( at June 24, 2019 3:11 pm)
Not really. This task is complicated by the fact this code runs with extended hours data included. At this time of the day the post-market session is over. However many stocks have very limited trade volume in the extended hours. Which means you can't determine the number of candles to look back. It's going to vary depending on how many of those extended hours candles have trade data.
( at June 24, 2019 8:20 pm)
Pete, I have tried the code below the last two days adding a volume and price criteria to my scan with No results being returned. I have setup alerts from my scans to be emailed to me and I find it odd that nothing is being alerted. Based on your screenshot below it seems like scan should work. Would you please check my scan and tell me what I am missing? I have tried different time frame like 10 mins with the Ext box checked and unchecked with no luck. http://tos.mx/HsreyD
( at June 26, 2019 4:34 pm)

I opened the shared scan you posted in the comment above. The checkbox for extended hours was unchecked and the time frame was set to 5 min. This pattern is exceptionally rare. I believe that the lower your time frame is the more rare this signal becomes. I suggest you start with a 15 min and 30 min time frames until you start getting results.

As a test, I ran the following code on a 15 min time frame with extended hours checked. I came up with 11 results using your filters. This code looks back 39 bars to see if any valid signals occurred. It just so happens that for a 15 min time frame stocks with high after-market volume will have 40 of those 15 min candles, but only after 8 pm Eastern.

I only changed the last line in the code:

plot scan = Highest(conditionTwo, 39) > 0;

( at June 26, 2019 7:23 pm)
Private answer

The source code for the VWAP study is dozens of lines so this is about the only time I will reference the built-in study rather than include the full code. Need to mention that because it is best practice to use the full code rather than a reference. Why? Because those built-in studies are subject to change.

Here is the code, with screenshot attached showing the result.

def data = reference VWAP()."VWAP";
def sessionStart = SecondsFromTime(930);
def conditionOne = sessionStart == 0 and open > data and close < data; def conditionTwo = conditionOne[1] and open < data and close > data;
plot scan = conditionTwo;

Marked as spam
Posted by (Questions: 36, Answers: 2121)
Answered on December 12, 2018 8:17 am