ATR Code

mini

Member
Hi, can someone help to rewrite the ATR Code not using the "AggregationPeriod.DAY" in the script but it will show the same daily ATR value in the chart since the scanner not allowed to scan the study in the aggregationPeriod. min. Thank you.


plot ATR = MovingAverage(averageType, TrueRange(high(period = AggregationPeriod.DAY), close(period = AggregationPeriod.DAY), low(period = AggregationPeriod.DAY)), length);
 
The scanner doesn't really operate in real time like that, it will only give you periodic updates every several minutes. One minute candles are a bit of a problem in that sense, especially if you want to be alerted the exact moment it happens. Would you settle for stocks which are just beyond either extreme of the ATR? That's doable.
 
The scanner doesn't really operate in real time like that, it will only give you periodic updates every several minutes. One minute candles are a bit of a problem in that sense, especially if you want to be alerted the exact moment it happens. Would you settle for stocks which are just beyond either extreme of the ATR? That's doable.
How about scan in 5 min or 10 min candles?
 
That's more doable. The second issue is that the scanner does not accept secondary aggregations. I would need to reconstruct the daily data from within the intraday data, and calculate the ATR manually from there. Although it may sound simple, this is actually a very difficult script to complete due to the limitations of the scanner. The scanner also only goes back so far into price history on smaller time frames, in this case, its only 15 days, So, it would have to be the 15 day ATR.

I would need to know if these limitations are acceptable to you. I would also like to ask you whether or not you're actually committed to using it, and please be honest. If you're just going to play around with it for a little while and then go try something else, its really not worth the trouble.
 
That's more doable. The second issue is that the scanner does not accept secondary aggregations. I would need to reconstruct the daily data from within the intraday data, and calculate the ATR manually from there. Although it may sound simple, this is actually a very difficult script to complete due to the limitations of the scanner. The scanner also only goes back so far into price history on smaller time frames, in this case, its only 15 days, So, it would have to be the 15 day ATR.

I would need to know if these limitations are acceptable to you. I would also like to ask you whether or not you're actually committed to using it, and please be honest. If you're just going to play around with it for a little while and then go try something else, its really not worth the trouble.
These limitations are acceptable as long as it can calculate the daily ATR. I only need the ATR length = 14. I try to fix secondary aggregation did not allowed in scanner for a long time. Thank you so much for your help!
 
I wrote a script to determine the number of bars available on a given aggregate relative to the number of those bars in a day. If there is not enough data, then no results will be found. If there is enough data, it will simply populate the results with the first symbols it encounters. This basically creates a form of yes/no output for testing.

Code:
declare lower;
Input Length = 14;
def Agg = GetAggregationPeriod();
def Date = GetYYYYMMDD();
def Start = RegularTradingStart(Date);
def End = RegularTradingEnd(Date);
def GetRegBars = (End - Start) / Agg;
def RegLength = GetRegBars * Length;
def EnoughBars = if !isnan(getvalue(close,-RegLength)) then yes else EnoughBars[1];
plot Scan = EnoughBars;

On the 30 minute aggregation, it only appears to be able to access 9 days worth of data. On the 15 minute aggregation, that number drops down to 5 days. This is a bit confusing, because all aggregations between 1 and 30 minutes are documented as having access to the same length of data in days. It is also measured in astronomical days, which I believe is their way of saying calendar days, my mistake.

There isn't enough intraday data available in the scanner to reconstruct the 14-Day ATR from within the intraday data.
 
Last edited:
I wrote a script to determine the number of bars available on a given aggregate relative to the number of those bars in a day. If there is not enough data, then no results will be found. If there is enough data, it will simply populate the results with the first symbols it encounters. This basically creates a form of yes/no output for testing.

Code:
declare lower;
Input Length = 14;
def Agg = GetAggregationPeriod();
def Date = GetYYYYMMDD();
def Start = RegularTradingStart(Date);
def End = RegularTradingEnd(Date);
def GetRegBars = (End - Start) / Agg;
def RegLength = GetRegBars * Length;
def EnoughBars = if !isnan(getvalue(close,-RegLength)) then yes else EnoughBars[1];
plot Scan = EnoughBars;

On the 30 minute aggregation, it only appears to be able to access 9 days worth of data. On the 15 minute aggregation, that number drops down to 5 days. This is a bit confusing, because all aggregations between 1 and 30 minutes are documented as having access to the same length of data in days. It is also measured in astronomical days, which I believe is their way of saying calendar days, my mistake.

There isn't enough intraday data available in the scanner to reconstruct the 14-Day ATR from within the intraday data.
Thank you so much! How to add your code to this script ?

plot ATR = MovingAverage(averageType, TrueRange(high(period = AggregationPeriod.DAY), close(period = AggregationPeriod.DAY), low(period = AggregationPeriod.DAY)), length);
 
Last edited:
I don't think you understand. It is not possible to make the script to your specifications.

The code I posted is just the code I used to discover that the scanner is even more limited than I previously believed.
 
I don't think you understand. It is not possible to make the script to your specifications.

The code I posted is just the code I used to discover that the scanner is even more limited than I previously believed.

I don't think you understand. It is not possible to make the script to your specifications.

The code I posted is just the code I used to discover that the scanner is even more limited than I previously believed.
Thank you so much for your help!
 

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
271 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