I am trying to create a scanner that can scan for stocks that have moved more than a certain percentage of its ATR (exponential, 14 day period). For example, I want to be able to find stocks that have moved 75% of their daily ATR in pre-market. Below is my current code. I am getting an error from thinkScript that says "Secondary period not allowed: Day." Any help would be greatly appreciated.
# Afterhours / Premarket ATR Scan input closing_time = 1559; input open_time = 0930; input price = close; input ATR_percent_change = 75.00; input ATRLength = 14; input averagetype = AverageType.EXPONENTIAL; input BasePeriod = AggregationPeriod.DAY; def ATR = MovingAverage (averagetype, TrueRange(high(period = BasePeriod), close(period = BasePeriod), low(period = BasePeriod)), ATRLength); 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, price); def valATR = ATR * (ATR_percent_change/100); def priceDiff = AbsValue(price - closing_price); def after_closing_bell = time_until_close <= 0; def before_opening_bell = time_until_open >= 0 ; def meet_scan_criteria; meet_scan_criteria = priceDiff >= valATR; plot scan = (after_closing_bell or before_opening_bell) AND meet_scan_criteria;