A recent build fixed an issue where division by 0 might not result in a "zero divide" error at runtime. The problem is in your code; a runtime crash is the expected result of division by 0.
You can disable the floating point dividers check in the project properties, then your advisor will stop crashing at runtime:
https://www.metatrader5.com/en/metaeditor/help/mql5storage/projects#properties
- Check floating point dividers: applications with the check disabled work a little faster, because the zero divide error is not checked during code execution.
But this will only mask the real problem - your code is unreliable.
your code is unreliable
iClose fails and returns 0. As a result of dividing by 0, you assign inf to returns[calcLoop] (if checking floating point dividers is disabled and the EA didn't crash). If returns[calcLoop] affects the trading logic, it will lead to incorrect trading:
- in the best case, the EA may send invalid trading orders that will not be executed
- in the worst case, trading orders that should not exist according to the strategy will be executed
https://www.mql5.com/en/docs/series/iclose
Return Value
The Close price of the bar (indicated by the 'shift' parameter) on the corresponding chart or 0 in case of an error. For error details, call the GetLastError() function.
- 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 2 years identical code is runing on errors now after this release.
For example i have added to my code DWEX Portfolio Risk Man Multi Position.mqh
and i am getting anerror
zero divide, check divider to avoid this error in (3939,86)
which used to work fine.
I think it has to do with open and close price, because when i ignore the error by skiping the part of codem i get errors related to my SL open and close price