Need help creating premarket scanner based on daily ATR

papipali

New member
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.


Code:
# 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)[1], close(period = BasePeriod)[1], low(period = BasePeriod)[1]), 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[1], 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;
 
Last edited:
Solution
Unfortunately, as covered in myriad other threads, there is a built in limit on one aggregation period for a scanner. There is no work around for a scan in which you want to compare values from multiple aggregations. There are workarounds for scans that can be run on different aggregations sequentially (scan on 1 day, save scan as dynamic watchlist, run second scan on first saved watchlist) but no methods for comparing multiple aggs.

-mashume
Unfortunately, as covered in myriad other threads, there is a built in limit on one aggregation period for a scanner. There is no work around for a scan in which you want to compare values from multiple aggregations. There are workarounds for scans that can be run on different aggregations sequentially (scan on 1 day, save scan as dynamic watchlist, run second scan on first saved watchlist) but no methods for comparing multiple aggs.

-mashume
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
422 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top