Click here to Login





                                                   ATR Calculation

  0

0
Mark Peterson
2014-10-22 02:01:59


There are differences between the values returned by the ATR indicator and a function implementation of the algorithm. I also created ATR in Excel. Finally I created a version that implements wilder's smoothing, but this made the difference worse.

Written Function (below) = Excel but != ATR(14)

Open/High/Close and period were confirmed to be the same.

The delta is much larger than can be explained by precision (up to 10%). Is there a different average to be used than Sma?

Thanks

http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:average_true_range_atr

-----Written Function-----

VectorD HighPrice = cFunctions.High;
VectorD LowPrice = cFunctions.Low;
VectorD ClosePrice = cFunctions.Close;
double PeriodLength = 14;
VectorD TrueHigh = TA.Max(HighPrice, TA.Ref(ClosePrice, 1));
VectorD TrueLow = TA.Min(LowPrice, TA.Ref(ClosePrice, 1));
VectorD TrueRange = TrueHigh - TrueLow;
VectorD ATR = TA.Sma(TrueRange, PeriodLength);


Comparison ATR QS = Internal QS indicator, ATR F = Above Code; ATR E = Excel Result; Diff is % difference

High Low Close ATR QS ATR F ATR E Diff
22.31 21.99 22.29 0.506019347 0.52429 0.52429 3.61%
22.7 21.81 22.27 0.520328528 0.52500 0.52500 0.90%
23.15 22.45 22.59 0.491892261 0.50929 0.50929 3.54%
23.67 22.76 22.83 0.475883973 0.48429 0.48429 1.77%
23.62 23.34 23.49 0.442490433 0.43571 0.43571 1.53%
24.15 23.61 23.68 0.450374312 0.45000 0.45000 0.08%
24.52 23.83 23.83 0.443480028 0.44571 0.44571 0.50%
24.88 24.49 24.63 0.416055415 0.40714 0.40714 2.14%
25.07 24.84 25.03 0.406521216 0.40000 0.40000 1.60%
24.95 24.7 24.87 0.420099772 0.39929 0.39929 4.95%
25.41 24.76 24.94 0.433184369 0.40429 0.40429 6.67%
25.43 25.12 25.28 0.416506244 0.37714 0.37714 9.45%
25.71 25.1 25.12 0.424699032 0.39000 0.39000 8.17%
25.75 25.5 25.69 0.410445111 0.36857 0.36857 10.20%
25.85 25.52 25.54 0.422787043 0.38286 0.38286 9.44%



QuantShare
2014-10-23 02:05:55

  0

"TR" calculation is ok. However, the average TR (ATR) is calculated using this formula:

Current ATR = [(Prior ATR x 13) + Current TR] / 14

You are doing a calculation using a simple moving average



Mark Peterson
2014-10-23 11:52:50

  0

Thanks - I tried this calculation and must have had an logic error.

This method for ATR is "Wilder's" smoothed algorithm.



No more messages
0




Reply:

No html code. URLs turn into links automatically.

Type in the trading objects you want to include: - Add Objects
To add a trading object in your message, type in the object name, select it and then click on "Add Objects"










QuantShare

Trading Items
ATR Trailing Indicator
ATR - Average True Range Drawing Tool
Fixed Bucket Calculation
Chandelier Exits
System Metrics v2.0

How-to Lessons
How to create a correlation matrix of several securities
How to automatically draw Fibonacci Retracement for each new stoc...
How to plot the relative performance of several stocks/indices
How to create a composite index/indicator
How to plot two different time frames in the same chart

Related Forum Threads
ATR stop and MM
ATR stop in chart
Composite Calculation
Screener ATR percentile filter
Set Global variable and running calculation Functions in MM scrip...

Blog Posts
Ranking system calculation methods
4 different weighted index calculation methods
Using Average True Range to Measure Intraday Volatility
3 ways to rank stocks in a trading system - Simulator and Potfoli...
Adding Trading Indicators and Formulas to a Chart









QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.