iHigh and iLow does not return anything.

 

I am running the following lines in my EA. When i run the EA for the first iHigh(Symbol(), PERIOD_D1, i)- iLow(Symbol(), PERIOD_D1, i) does not seem to return anything. The value of averageDailyRange after the call is 0. Then after that it seems to work fine, it's only the first time that it fails. Why does it fail? What can I do to prevent this?

for (int i=1; i<=ADRDays; i++) {
averageDailyRange = averageDailyRange + (iHigh(Symbol(), PERIOD_D1, i)- iLow(Symbol(), PERIOD_D1, i));
}
averageDailyRange = averageDailyRange / ADRDays;

The value of ADRDays is 30.
I use an M15 chart.
In my options the Max Bars In History and Max Bars In Chart is set to 50,000.

Thanks
Gosta


 

use NormalizeDouble()

regardless wat's wrong with iATR()

 

The problem is that iHigh - iLow returns 0, so I can't see how rounding the value would help. I do round later in the code but did not want to round every iteration in order to keep the rounding error as small as possible.

Thanks for the tip regarding iATR. It is possible that I am inventing the wheel here but I don't know exactly what iATR does and the doc is pretty vague so this way at least i have full control (apart from the error at virgin installations). I think it has to do with the iHigh and iLow array not being populated all the way back, or something like that. So even if iATR would turn out to be an ideal replacement, I would still like to understand what is going wrong.

Anyone with any ideas?

Gosta

 

first i checked your code & it's working just fine second

iATR(NULL,PERIOD_D1,30,shift);
is gonna give u exactly the same result
Reason: