I think MT4 ATR code is wrong?

 

Hi, am not an expert, thus I need to seek your support, I know I am wrong but:

According to the definition/formula of ATR, it looks to me that the ATR code in MT4 is wrong.

See, the formula to calculate ATR is :  TR=max[(high-low), abs(high-close_prev), abs (low-close_prev)] according to wikipedia.

But in MT4's ATR code , it code the looping as : 

----qte----

//--- the main loop of calculations

   for(i=limit; i<rates_total; i++)

     {

      ExtTRBuffer[i]=MathMax(high[i],close[i-1])-MathMin(low[i],close[i-1]);

      ExtATRBuffer[i]=ExtATRBuffer[i-1]+(ExtTRBuffer[i]-ExtTRBuffer[i-InpAtrPeriod])/InpAtrPeriod;

     }

//--- return value of prev_calculated for next call

   return(rates_total);

------- unqte ----


My question is : if we need close value of the previous bar, then we need to say close[i+1], instead of [i-1], doesn't it ? 


Many thanks friends.

 
Read the documentation about ArraySetAsSeries().
 
Alain Verleyen:
Read the documentation about ArraySetAsSeries().

Thank you Alain, let me study it again. cheers.