No need to reinvent the wheel. ADR = ATR of Daily Bars. So just use the iATR() function instead, with PERIOD_D1 for the timeframe period.
- www.mql5.com
Average Daily Range (ADR) is a Simple Moving Average (SMA) of the High/Low range, while MetaTrader's ATR is the SMA of the True Range (instead of the High/Low range).
So yes, they are different, but the differences are negligible.
I have solved the problem. Sundays should be avoided when calculating the average.
Thanks
Hi,
I'm developing this indicator, an ADR for MT5.
The algorithm is, get the sum of daily range high and low from last N days (14 in my sample), begining from yesterday, and divide it into N periods (14). Getting the average.
I don't know which is the problem but I'm comparing with an MT4 indicator and the result is different.
The function get by parameters the date of current bar (lower timeframes than daily), and returns the ADR.
Could you revise my code for any mistake?
This is my code:
Thank you very much
- sadegh Hejazi #: You must use:
double adr = adr_acum / (adr_count-1);
You must not use count-1. Average is the sum divided by count. If the count was one item, do you divide by zero?
- powerbucker: This is my code:You want to process 14 items. Before the loop starts, you have processed zero, not one. Therefor your count is wrong after the loop exit.
double adr_acum = 0; int adr_count = 1; while (adr_count <= 14)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I'm developing this indicator, an ADR for MT5.
The algorithm is, get the sum of daily range high and low from last N days (14 in my sample), begining from yesterday, and divide it into N periods (14). Getting the average.
I don't know which is the problem but I'm comparing with an MT4 indicator and the result is different.
The function get by parameters the date of current bar (lower timeframes than daily), and returns the ADR.
Could you revise my code for any mistake?
This is my code:
Thank you very much