How to add a time filter to scan


Category:
0
0

How to target or filter scans with a specific time period filter.

For example I would like to use your previous code you provided me

input xPercent = 10.0;
def percentChange = 100 * (close / close[1] – 1);
plot scan = AbsValue(percentChange) > xPercent;   ” and it is to only apply to the first two bars of the day (1 hour chart)”  Bar Format

Or  between 9am and 11am      Time Format

 

Marked as spam
Posted by (Questions: 3, Answers: 2)
Asked on December 7, 2017 9:17 am
218 views
0
Private answer

Since your request specifies the first two hourly bars of the trading day I will provide a very simplistic solution. You only need to check if the current bar is a different day than the previous bar. When that is true we know we have the first bar of the new day.

def newDay = GetDay() <> GetDay()[1];

This gives us a True/False variable that tells us when we are on the first bar of a new day. This requires us to uncheck the box for Extended Trading Hours. So we are only working with Regular Market Hours.

Next, we use this True/False variable in a plot statement in a way to evaluates to True for the first two bars of the trading day.

plot scan = newDay and newDay[1];

That’s it. Place both of these lines together in a new study filter applied to the hourly time frame, unchecking the box to turn off Extended Hours. You don’t have to add these lines to the original code. Just add it as a new Study Filter and it will work in combination with all the other filters in your scan.

 

Marked as spam
Posted by (Questions: 37, Answers: 4086)
Answered on December 7, 2017 11:41 am
0

had an issue with the code

I entered it by itself in its own study and also with in this and other studies
input xPercent = 10.0;

def percentChange = 100 * (close / close[1] – 1);
def newDay = GetDay() GetDay[1];
plot data = AbsValue(percentChange) > xPercent;

Getting Red Highlight on the second GetDay

Expected double
No such variable: GetDay at 3:26″

( at December 7, 2017 2:54 pm)
0

Yes, sorry. The second one is missing the parenthesis. Sorry, did this from memory and did not test it. I just updated my answer to correct the typo so future visitors will not be tripped up. Thanks.

( at December 7, 2017 3:30 pm)
0
Private answer

screen shot

Attachments:
Marked as spam
Posted by (Questions: 3, Answers: 2)
Answered on December 7, 2017 2:58 pm