ATR (Average True Range) calculation

Questions about MultiCharts .NET and user contributed studies.
tradetree
Posts: 81
Joined: 29 Apr 2013
Location: www.threefoldmarkets.com
Has thanked: 12 times
Been thanked: 16 times
Contact:

ATR (Average True Range) calculation

Postby tradetree » 07 Dec 2013

I have been porting an algorithm from another platform, and it contained the ATR. I discovered that Multicharts implementation of ATR is incorrect. I will show a simple example below that uses a 10 bar ATR. The ATR is made up of True Range values, where the final value is an EMA of the True Range values. MC uses an SMA rather than an EMA. This is incorrect.

Here are 10 TR values:
9.4, 7.9, 5.2, 2.7, 4.9, 4.3, 6.3, 6.3, 4.3, 2.5

The sum of these TR values = 53.8 and the 10 period SMA of this is 5.38. MC gives the 10 period ATR as 5.38 (the SMA). This is erroneous.

The *approx* correct value for the 10 period ATR over this series is 5.0342, but as it is an EMA you would need all prior values to correctly calculate it. An EMA is "exponential" which means it relies on all past values. This is just the correct value for my series which is not all listed here.

Investopedia has the formula wrong too! Most other references on ATR will give the correct formula, but the clearest correct one is:
http://en.wikipedia.org/wiki/Average_true_range

What is annoying about Investopedia is that they actually reference Wilder's book, "New Concepts in Technical Trading Systems" and then ignore his formula. Wikipedia has it right.

For reference purposes here is my code:

Code: Select all

true_range = this.TrueRange(0); // Get TrueRange
true_range = this.AverageTrueRange( 1, 0 ); // Same as TrueRange
atr = this.AverageTrueRange( 10, 0 ); // Incorrect ATR returned

NW27
Posts: 177
Joined: 25 Dec 2010
Has thanked: 40 times
Been thanked: 85 times

Re: ATR (Average True Range) calculation

Postby NW27 » 08 Dec 2013

In my Elder book it states it is the AVERAGE of the True Range for the last n Periods. Not Exponential Average of the Last n periods.

Your reference to Wikipedia having it right also shows the formula as been the average not exponential average. I can see the comment in the second line where they made a typo stating Exponential but if you look at the formula it is a standard average as per the actual name of the indicator. "Average True Range"

tradetree
Posts: 81
Joined: 29 Apr 2013
Location: www.threefoldmarkets.com
Has thanked: 12 times
Been thanked: 16 times
Contact:

Re: ATR (Average True Range) calculation

Postby tradetree » 08 Dec 2013

It is fascinating that even when I post that the ATR is wrong, people post back that it is right! Your post has no reliable information. Ok, so you say, "if you look at the formula it is a standard average". Here is their formula:
ATR[t] = ( ATR[t-1] x (n-1) + TR[t] ) / n.

This is the EMA!!!

Now I'm thankful you are trying, and the last thing I want is a flame war, but please, if you post again, please put some facts together. Please put a formula up with a reference to Welles Wilder, the creator of the ATR. There are SATR and other variations, but there is only one single formula for the ATR. Is uses the EMA. If I were wrong about that, then you would be able to reference where Welles Wilder uses the SMA in the ATR formula.

Another reference:
http://www.wikinvest.com/wiki/Average_True_Range

It is really stressful when people post contrary opinions without doing a knowledgeable investigation because I know how hard it is already going to be to convince MC people to fix it. I already have my own fixed ATR that matches the standard, and I'm using this corrected ATR, but it should be correct in the code base as well.

Here is an example where someone is describing a system based on ATR, and he assumes we are all talking about the same formula:
http://www.tradingmarkets.com/recent/ho ... 77507.html

If we are not talking about the same formula then we will get into all kinds of trouble.

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: ATR (Average True Range) calculation

Postby JoshM » 09 Dec 2013

It is fascinating that even when I post that the ATR is wrong, people post back that it is right! Your post has no reliable information.

(...)

Now I'm thankful you are trying, and the last thing I want is a flame war, but please, if you post again, please put some facts together. Please put a formula up with a reference to Welles Wilder, the creator of the ATR. There are SATR and other variations, but there is only one single formula for the ATR. Is uses the EMA. If I were wrong about that, then you would be able to reference where Welles Wilder uses the SMA in the ATR formula.
(...)
Speaking of reliability, an issue with this discussion is that you reference Wikipedia, but that Wikipedia in turn references EarnForex.com for the formula. And the WikiInvest link has no references. This is not to say you're not right, but that it will be hard to determine what is "true" unless someone has the actual Wilder (1978) book.

For what's worth, StockCharts also uses an EMA version.

tradetree
Posts: 81
Joined: 29 Apr 2013
Location: www.threefoldmarkets.com
Has thanked: 12 times
Been thanked: 16 times
Contact:

Re: ATR (Average True Range) calculation

Postby tradetree » 09 Dec 2013

Josh,
Thanks for pointing that out, but there is a reference in the wiki, "J. Welles Wilder, Jr. (June 1978). New Concepts in Technical Trading Systems. Greensboro, NC: Trend Research. ISBN 978-0-89459-027-6". Also, I have a platform that has it correct, so I know the calculation exactly.

My post was meant to alert MC about the discrepancy and have them look into it. There is no question there is a problem, but for complete accuracy we need the MC official feedback.

I also have created a C# class to create the correct version. Once we resolve references I will release it for others to use. I am doing a bit-exact comparison with the other platform to verify. Once it is verified with the Wilder reference it will be complete.

tradetree
Posts: 81
Joined: 29 Apr 2013
Location: www.threefoldmarkets.com
Has thanked: 12 times
Been thanked: 16 times
Contact:

Re: ATR (Average True Range) calculation

Postby tradetree » 09 Dec 2013

It is page 23 in "J. Welles Wilder, Jr. (June 1978). New Concepts in Technical Trading Systems. Greensboro, NC: Trend Research. ISBN 978-0-89459-027-6". He calculates it based on a 7 period ATR, so it is the EMA for 7 periods in his example. The period can be kept at 7 or any other integer greater than or equal to 1 can be used. In my class, I force the period to be one (if it is less) so there is no possible divide by zero error.

Another critical point to the calculation is the initialization period. He covers this on page 24. It is the SMA for the first n-period samples. No doubt this is where programmers get confused. They see the initialization is the SMA and keep using that even though on both page 23 and 24 Wilder points out it is the EMA after the first n samples.

I would ask MC to officially comment on this finding so we can get it entered as a bug for future resolution.

- www.threefoldmarkets.com
- Threefoldmarkets LLC

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: ATR (Average True Range) calculation

Postby Henry MultiСharts » 10 Dec 2013

We will check that.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: ATR (Average True Range) calculation

Postby Henry MultiСharts » 11 Dec 2013

Tradetree, our discussion forum is for constructive dialogue. All users are free to post their opinion. If you disagree with someone’s opinion – there is no point being offensive or sarcastic to this forum member.

Back to ATR calculation. As it has been already discussed – there are various ATR calculation formulas over the Internet. Some people consider one calculation to be the proper one, some others find a different one more suitable for them, even if it goes on a contrary with the function inventor (yes, this is how the traders think). The current ATR implementation has been in MultiCharts since Day 1. A lot of people were using it for a long time already and have not complained about it. If we will change the current ATR calculation – it will be a code breaking change for a lot of people. This is not something we would like to do.

The benefit of MultiCharts is that you can create the function you need and use it in MultiCharts. We are glad that you have created the study that suits your needs and helps you to achieve your goal. We will be grateful if you can post your function in User Contributed Ыtudies section so the other users can benefit from it as well.

tradetree
Posts: 81
Joined: 29 Apr 2013
Location: www.threefoldmarkets.com
Has thanked: 12 times
Been thanked: 16 times
Contact:

Re: ATR (Average True Range) calculation

Postby tradetree » 12 Dec 2013

Fair enough regarding being polite, but I anticipated that it would be an up-hill battle to get the official and industry standard ATR accepted by MC. I was a bit stressed with the apparent lack of interest in the correct formula. I don't have a problem with anyone challenging any of my assumptions, formula, or expected results. I really don't. I am corrected many times a day in my work as an engineer and trader, as it is part of life if you are an objective person, especially in the sciences. But I was taken off-guard by the confidence in the wrong analysis. It just threw me, but perhaps I misread the intent of the post.

Also, the previous platform I used had technical support staff that would not acknowledge the real issues at hand. You and your staff are open and even handed, but keep in mind that many times (with the prior platform) it was necessary to push hard to even get acknowledgement of basic facts. There is always inertia to change, as you can see even with your response.

I also understand your point regarding the installed base, and that it would be disruptive to users who rely on the old, even though incorrect, version of the ATR. At this point it doesn't really matter to me as an individual user, although it is a bit concerning regarding discussions of strategies with other traders going forward.

I will be more than happy to post the ATR.

cjwik
Posts: 4
Joined: 13 Dec 2013
Been thanked: 1 time

Re: ATR (Average True Range) calculation

Postby cjwik » 13 Dec 2013

I was also starting to look into this as it seemed that something was "wrong" with the MC implementation of the indicator.

Henry MultiСharts, wouldn't it be appropriate to add this correct/original version to MC as well? I can understand that you don't want to change the current version, but to add this version as well maybe would be appropriate as one might be able to argue this as a flaw of the product as-is. Of a otherwise very nice product.

tradetree, if you would find the time to do the coding of it I would be very happy if you would like to share it.

/Carl-Johan

tradetree
Posts: 81
Joined: 29 Apr 2013
Location: www.threefoldmarkets.com
Has thanked: 12 times
Been thanked: 16 times
Contact:

Re: ATR (Average True Range) calculation

Postby tradetree » 13 Dec 2013

I have posted the "_ATR" indicator in the "User Contributed Studies" section. I have tested it, so please let me know if it works out for you as well or if there are any problems. It is visibly different from the Average True Range from MC as it reacts much more quickly to ATR changes.


Return to “MultiCharts .NET”