ADR Indicator for MT5

 

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:


double getADR(datetime dateBar)

{
   int dayIndex = iBarShift( _Symbol, PERIOD_D1, dateBar, true);

   double adr_acum = 0;
   int adr_count = 1;

   while (adr_count <= 14)
   {
      double diff = iHigh(_Symbol, PERIOD_D1, dayIndex+adr_count) - 
                    iLow(_Symbol, PERIOD_D1, dayIndex+adr_count);

      adr_acum += diff;
      adr_count++;
   }

   double adr = adr_acum / adr_count;

   return adr;
}


Thank you very much

 
I think it was "ADR == ATR".
 
israelhernandoI'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? 

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.

Documentation on MQL5: Technical Indicators / iATR
Documentation on MQL5: Technical Indicators / iATR
  • www.mql5.com
iATR - Technical Indicators - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Fernando Carreiro:

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.

ATR uses different calculations than the ADR doesn't it?

 
Keith Watford: ATR uses different calculations than the ADR doesn't it?

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

 
powerbucker:

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

You must use:

double adr = adr_acum / (adr_count-1);
 
  1. 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?


  2. powerbucker: This is my code:
       double adr_acum = 0;
       int adr_count = 1;
    
       while (adr_count <= 14)
    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.
Reason: