Problem with iATR ??
I wrote a small test indicator to display the iATR values.
This indicator also displays the difference between the High and Low values for the first few candles.
When I manually calculate the ATR for periods 1,2, and 3 the result agrees with the iATR value.
However, any iATR period above 3 does not agree with the manual calculations.
I must be doing something wrong, but I can't see the problem.
Code: Select all
#property indicator_chart_window
int start()
{
static datetime currentBar = 0;
if (currentBar == Time[0]) return(0);
else currentBar = Time[0];
Print("[1] ",DoubleToStr(MathAbs(High[1] - Low[1]),5),
" [2] ",DoubleToStr(MathAbs(High[2] - Low[2]),5),
" [3] ",DoubleToStr(MathAbs(High[3] - Low[3]),5),
" [4] ",DoubleToStr(MathAbs(High[4] - Low[4]),5),
" [5] ",DoubleToStr(MathAbs(High[5] - Low[5]),5));
Print("ATR1 ",DoubleToStr(iATR(NULL,0,1,1),5));
Print("ATR2 ",DoubleToStr(iATR(NULL,0,2,1),5));
Print("ATR3 ",DoubleToStr(iATR(NULL,0,3,1),5));
Print("ATR4 ",DoubleToStr(iATR(NULL,0,4,1),5));
Print("ATR5 ",DoubleToStr(iATR(NULL,0,5,1),5));
return(0);
}