I see that the original request was for a scan that would function in premarket as well as regular session hours. I looked at the built-in scan filters and found one named “AfterHours_Percent_Change”. It’s listed as a Study Filter, under the section named “Price Performance”.
This built-in study does almost everything we need. However it does not function during regular session hours and only covers one direction of percent change. It’s either greater than x percent or less than x percent. There is no way to do both directions.
So I copied the code from that built-in Study Filter and modified. I have not tested this so I am not sure if it works as expected. So test it out and let us know. It is intended to run on an intraday time frame and be sure to check the box for extended hours.
input closing_time = 1559;
input open_time = 0930;
input price = close;
input percent_change = 3.00;
def time_until_close = SecondsTillTime(closing_time);
def time_until_open = SecondsTillTime(open_time);
def closing_bell = time_until_close == 0;
rec closing_price = CompoundValue(1, if closing_bell then price else closing_price[1], price);
def after_closing_bell = time_until_close <= 0; def before_opening_bell = time_until_open >= 0 ;
def afterhours_percent_change = 100 * (price / closing_price - 1);
def meet_scan_criteriaGT = afterhours_percent_change >= percent_change;;
def meet_scan_criteriaLT = afterhours_percent_change <= percent_change;;
plot scan = meet_scan_criteriaGT or meet_scan_criteriaLT;
Thank you, and if I wanted to widen this range to exclude anything in the range of -10% to +10%. How will I go about doing that?
Will this criteria factor in premarket movements at the scan is most important before 9:30am est
Odd that you would ask that. Really has nothing to do with the code. Don’t you see how the math is computed? Times 1.03 and time 0.97? That is plus 3% and minus 3%. Change those values to whatever percent you want.
This code would be set to daily time frame. So it does not even factor in any premarket data. All it does is compare today’s current close to yesterday’s close.