Check operator precedence for possible error; use parentheses to clarify precedence

 

Hello, MQL5 Community

Please assist with the "Warning" Message from my MetaEditor code:

I'm currently working on an EA and have been unsuccessful in resolving the message.

The error appears to be caused by highlighted operators in my initial code below:

if(remain==0 && Ask>maVal && OrdersTotal()==0 || MAFilter == false && isUseFilters)

In this condition check, I'm using a Commodity Channel Index (CCI) and a moving average (MA) indicator to confirm entry into the market in either direction.


Your support is highly appreciated.

 
OTMT HowardPlease assist with the "Warning" Message from my MetaEditor code: I'm currently working on an EA and have been unsuccessful in resolving the message. The error appears to be caused by highlighted operators in my initial code below:
if(remain==0 && Ask>maVal && OrdersTotal()==0 || MAFilter == false && isUseFilters)

In this condition check, I'm using a Commodity Channel Index (CCI) and a moving average (MA) indicator to confirm entry into the market in either direction.

Your logic is unclear, and that is why it is warning you. Since you have not provided your full code nor an explanation of the "logic" of your if statement above, it will remain unclear to us humans as well.

Also, please note that if the variable "remain" is of the "double" type, then the part "remain == 0" might also fail.

You should also not depend on "OrderTotal()==0" as that will clash with others EAs running. You should count the number open positions taking into account the symbol and magic number.

When adding code, please use the "</>" icon or Alt+S for it, as I have done now.

I will however try to "guess" at your logic. Is it perhaps this?

if( ( remain == 0 && Ask > maVal && OrdersTotal() == 0 ) || ( !MAFilter && isUseFilters ) )

Or is it perhaps this?

if( remain == 0 && Ask > maVal && ( OrdersTotal() == 0 || !MAFilter ) && isUseFilters )

Without a proper explanation from you or the full source, we can only speculate. By the way, "!MAFilter" is the same as "MAFilter == false". The exclamation symbol "!" is a boolean operator.

 

 Hei,  Fernando Carreiro


Thank you very much for your support with my recent code.

Your idea was exactly what I was looking for. 

Reason: