You have to check every part of the code where you are dividing. For example:
step through the code and check the variable's values.
https://www.mql5.com/en/articles/654
ShtZone / (RangeHi-RangeLo)If for some reason RangeHi-RangeLo results in zero, you would have the divide by zero error. Use the debugger to
step through the code and check the variable's values.
https://www.mql5.com/en/articles/654
Debugging MQL5 Programs
- www.mql5.com
This article is intended primarily for the programmers who have already learned the language but have not fully mastered the program development yet. It reveals some debugging techniques and presents a combined experience of the author and many other programmers.
Alexandre Borela #:
You have to check every part of the code where you are dividing. For example:
If for some reason RangeHi-RangeLo results in zero, you would have the divide by zero error. Use the debugger to
step through the code and check the variable's values.
https://www.mql5.com/en/articles/654
You have to check every part of the code where you are dividing. For example:
If for some reason RangeHi-RangeLo results in zero, you would have the divide by zero error. Use the debugger to
step through the code and check the variable's values.
https://www.mql5.com/en/articles/654
Thanks! I will definitely check that out to try and fix the divide by zero error. As far as the booleans themselves though, am I able to code it the way I have it above, or should i be breaking each one down into two steps using an if statement?
Erik Volk #:
You can code it that way if the resulting logic is what you want, the most important thing is to keep the code readable and sometimes I too create temporary booleans to Thanks! I will definitely check that out to try and fix the divide by zero error. As far as the booleans themselves though, am I able to code it the way I have it above, or should i be breaking each one down into two steps using an if statement?
make the intent clear. The only thing that I would change is remove the "== true", it's unnecessary in that case:
if (IsFirstTime && ShtRev && ShtSzeCatLrg && ShtCPHi)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Very new to mql4 and programming in general. I currently have several boolean variables declared in this fashion:
bool ShtRev = High[0] >= HiZone && MidPoint < Low[1];
bool ShtSzeCatLrg = ShtZone / (RangeHi-RangeLo) <= SizeCatLrgMax && ShtZone / (RangeHi-RangeLo) >= SizeCatMdMax;
bool LngSzeCatLrg = LngZone / (RangeHi-RangeLo) <= SizeCatLrgMax && LngZone / (RangeHi-RangeLo) >= SizeCatMdMax;
then, I feed those into an if statement. Basically, if all of these market conditions are true at the same time, send an order:
if(IsFirstTime == true && (ShtRev == true) && (ShtSzeCatLrg == true) && (ShtCPHi == true))
The code compiles, but when I backtest, no trades are taken when i know there should be, and I get 'global initialization failed' and 'zero divide' errors. I'm pretty sure there's multiple issues with how i've built the EA so far, but I'm wondering if part of my issue is you can't declare booleans in this way. Should I be doing something like this instead?
if(RangeHi-RangeLo <= SizeCatLrgMax && (ShtZone / (RangeHi-RangeLo)) >= SizeCatMdMax)
{bool ShtSzeCatLrg = true;
}