Working boolean condition returns warning when compiling: "expression is always false" - I must be doing something wrong
-
Hi Radoslav,
I have a question regarding using boolean values inside conditions. I must be doing something wrong...
Whenever I make a condition like the one you see on Init in the shared example below, it works just fine, but MetaEditor returns this warning when trying to compile the mq4 file: "expression is always false".
Again, it works just fine and I understand a boolean value is basically just 0 or 1 internally, but maybe you know what I could do to prevent the warning message when using bool conditions?Here's a working example where the condition "on Init" triggers block 6 "on Tick" to go on: https://fxdreema.com/shared/IaoNWwzae
Here's the warning MetaEditor shows when compiling: https://drive.google.com/file/d/0B9owZMPMRrkSRlpDLTZBZVpEOEk/viewAny advice or help would be much appreciated!
Best regards,Saf
-
These warnings appear because of some additional checks in "Condition". Thei check whether one of the operands is equal to EMPTY_VALUE or not. The idea is to prevent "Condition" from activating it's outputs if one of both operands is EMPTY_VALUE, which sometimes happens with indicators or objects. Now there are warnings because the compiler can see that the operand always equals to true. I just don't have additional optimization of the output code to remove these checks in this situation.
Warnings are not scary in general. They are hints that something can be written better, but this is universal EA Builder after all and the code that it generates is not very compact and optimized, as you can see
But it works most of the time! -
Ah thanks so much for the extensive answer!
Right after posting this question though, I realised that I already answered my own question by saying that boolean values are just a numeric (0 or 1) value internally. So the actual answer to my question should be: Make the right operand "Numeric" "1", instead of "Boolean" "True", and there you go! The warning message is gone!

(correct me if I'm wrong though)https://fxdreema.com/shared/uFAvkIh7b
Gotta love fxd

Thanks again!Cheers
-
It will work. Data types are a little bit weird in MQL4/MQL5 and in the C/C++ world, especially floating numbers, but comparing booleans with 1 or 0 normally works.