# Request for: average ATR range for same bar from different period

#### astrostrider

##### New member
Greetings from Europe,
Is it possible to use price information for the same bar in different time periods to construct a moving ATR band? Fore example using a 5-min bar at 9:30-9:35 over the last 20 days to computer ATR for that particular bar, etc. I think it's helpful for intraday trading as it factors in intraday time-period based volatilities. I tried to do it myself but I am not a developer and there is this saying "old dog doesn't learn new tricks". Would appreciate it very much if someone can help. Thanks a lot.

Greetings from Europe,
Is it possible to use price information for the same bar in different time periods to construct a moving ATR band? Fore example using a 5-min bar at 9:30-9:35 over the last 20 days to computer ATR for that particular bar, etc. I think it's helpful for intraday trading as it factors in intraday time-period based volatilities. I tried to do it myself but I am not a developer and there is this saying "old dog doesn't learn new tricks". Would appreciate it very much if someone can help. Thanks a lot.

See if this method helps. It uses 'thisday snippet' to capture each day's atr, starting with thisday at 0 for today and the thisday between 1 to 20 for the past 20 days, all at 0935's bar.

Ruby:
``````input lookback = 20;
input time     = 0935;
def ymd        = GetYYYYMMDD();
def candles    = if IsNaN(close) then candles[1] else close;
def capture    = candles and ymd != ymd[1];
def dayCount   = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
def thisDay    = (HighestAll(dayCount) - dayCount) ;
def atrpast    = if Between(thisDay, 1, lookback) and SecondsFromTime(0935) == 0 then atrpast[1] + Average(TrueRange(high, close, low), 1) else atrpast[1];
def atrtoday   = if thisDay == 0 and SecondsFromTime(0935) == 0 then Average(TrueRange(high, close, low), 1) else atrtoday[1];
AddLabel(1, "ATR@" + time + " - Today: " + atrtoday + "; Last " + lookback + " days: " + (atrpast / lookback), if atrtoday > (atrpast / lookback) then Color.LIGHT_GREEN else Color.LIGHT_RED);``````

Thank you SleepyZ. I was able to modify someone's code to get time-segment based ATRs for each bar, but have difficulties to apply to a reference curve. I would like to have it pre-plotted in advance but all MAs are laggard. I am trying to find a price projection curve, which probably render this idea useless.

87k+ Posts
359 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?