MovingAverage length ?

rubixcube49

New member
Plus
If my question has already been answered elsewhere, just pass me the link - no need to repeat it here.

The last parameter in MovingAverage is length, but I can't tell what that means in context.

Here is a relevant snippet of code:
--------------------------------------------------
input length = 7;
input ATRaverageType = AverageType.WILDERS;
def ATR = MovingAverage(ATRaverageType, TrueRange(high, close, low), length);
----------------------------------------------------
I'm using this in a 1D/5m chart. I want length to represent 7 days, not 7 bars.

What does it mean here?

Thank you in advance.
 
In that context, it means seven bars. Changing it to seven days would also depend on context - seven days worth of 5 minute true range, or the true range of seven complete Daily bars?

For the latter,
Code:
input length = 7;
input averageType = AverageType.WILDERS;
input agg = aggregationPeriod.DAY;
plot ATR = MovingAverage(averageType, trueRange(high(period = agg),close(period = agg),low(period = agg)), length);

The other scenario is far more complex. You would need to dynamically fold (loop) backwards through the prior bars, searching for, and terminating the loop, at the bar that represents seven days ago from starting point, while tabulating the ATR along the way. I can show you how to do if it that's what you're actually going for, but if not, I'd rather not waste my time until I know for sure.
 
Joshua, thanks for your reply and a solution, which is spot on given that I was looking for the true range of seven complete Daily bars.

So, is it the case that the aggregation period of the chart defines the value of MovingAverage length?
 

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