My EA was giving me an intermittent divide by zero error while doing backtests of AUD/NZD. The journal pointed the source of the error to my lot size calculation below, specifically the (1/NUrate) part.
It was not a consistent error, sometimes it would occur and sometimes it wouldn't, making it hard to pinpoint the exact source of the error and making it even harder to verify if I fixed it.
At the end of the day I thought it might be because I was using the 0 bar for the iClose("NZDUSD",0,0) so I changed it to:
I am aware that there might be an issue when trying to run a test using the zero bar of another timeframe of the same symbol, so I thought that might be also true of trying to use another symbol's 0 bar.
As I continue testing, time will tell if the issue crops up again but maybe someone knows for sure if I have fixed the problem?
Edit: additional info, it seems to be something to do with the dates I choose to test. If it starts too early, the divide by zero error might occur.Did you read the documentation of iClose()?
Returned value
Close price value for the bar of specified symbol with timeframe and shift. If local history is empty (not loaded), function returns 0. To check errors, one has to call the GetLastError() function.
So how does one ensure that the local history is always loaded?
If I just had the NZDUSD chart open in the background as well as the AUDNZD chart running the EA, would that always ensure that the local history is loaded?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
My EA was giving me an intermittent divide by zero error while doing backtests of AUD/NZD. The journal pointed the source of the error to my lot size calculation below, specifically the (1/NUrate) part.
It was not a consistent error, sometimes it would occur and sometimes it wouldn't, making it hard to pinpoint the exact source of the error and making it even harder to verify if I fixed it.
At the end of the day I thought it might be because I was using the 0 bar for the iClose("NZDUSD",0,0) so I changed it to:
I am aware that there might be an issue when trying to run a test using the zero bar of another timeframe of the same symbol, so I thought that might be also true of trying to use another symbol's 0 bar.
As I continue testing, time will tell if the issue crops up again but maybe someone knows for sure if I have fixed the problem?
Edit: additional info, it seems to be something to do with the dates I choose to test. If it starts too early, the divide by zero error might occur.