Manual ATR function vs inBuilt iATR - page 2

 


Just calculate the number of bars for the ATR and no smoothing


//----------------------- Average True Range ------------------------------------------------

//----------------------- Average True Range -------------------------
double ATR(int period, int bar)
{
   double sum=0;
   for (int x=bar; x<(bar+period); x++) 
     { sum += MathMax(iHigh(NULL,TF,x),iClose(NULL,TF,x+1))-MathMin(iLow(NULL,TF,x),iClose(NULL,TF,x+1)); }
   return(sum/period);
}
//--------------------------------------------------------------------

//-------------------------------------------------------------------------------------------------
 
maximo # :
Just calculate the number of bars for the ATR and no smoothing
Therefore, this is a TR, not an ATR
 
Gerard William G J B M Dinh Sy #:
Therefore, this is a TR, not an ATR


It is the 'sum' of True Range that makes it Average True Range.   ie.  sum +=  True Range

Wilders smoothing is a separate formula derived from the input Length.   Input Length*2-1  

 
maximo # :


It is the 'sum' of True Range that makes it Average True Range.   ie.  sum +=  True Range

Wilders smoothing is a separate formula derived from the input Length.   Input Length*2-1  

You're mixing everything up.

If you remove the smoothing, it's no longer an ATR, it's a TR (True Range) , period.

We cannot talk about an average indicator if we don't average anything.

Furthermore, your formula only makes sense for a mathematical equivalence:

An ATR Wilder over a period N effectively corresponds to an ATR EMA with a period of N period* 2 - 1 .

Example: ATR Wilder 14 = ATR EMA 27.

 

No.


The True Range in the Average True Range (ATR) measures the greatest of the following three values:

  1. Current period's high minus the current period's low

  2. Absolute value of the current period's high minus the previous period's close

  3. Absolute value of the current period's low minus the previous period's close 

Which corresponds to the code:  

MathMax(iHigh(NULL,TF,x),iClose(NULL,TF,x+1))-MathMin(iLow(NULL,TF,x),iClose(NULL,TF,x+1));

The Average corresponds to the summation of a number of the above True Ranges.  Hence the term Average True Range.   

It is a Simple Moving Average of True Ranges.  ATR=SMA(TR);   There is no EMA calculation here. 

Wilders smoothing factor is optional and is not a requirement. 

The ATR from MetaQuotes Ltd. does not use Wilders smoothing factor.      


Reference calculations  https://www.macroption.com/atr-calculation/ 

 
maximo #:
No
I give up. Do as you want