Warning Expression is always false

 
Hi, I have an EA that worked just fine with the meta trader 4 platform.. however I just recently updated to build 610 and now the EA does not work... I compiled it with the new Meta Editor and am now getting two warnings .. Both are the following Expression is always false, Not sure why this would stop the EA from entering trades, but the EA will not enter any trades what so ever ... the problem hi-lighted below is the code -> if(Deleted < 0) and also in another function -> if(Closed < 0) .... always returns false, any suggestions as to why Build 610 sees this differently ? Thanks
bool CloseSellOrder(string argSymbol, int argCloseTicket, double argSlippage)
  {
    OrderSelect(argCloseTicket,SELECT_BY_TICKET);
    
    
    if(OrderCloseTime() == 0)
      {
        double CloseLots = OrderLots();
        
        while(IsTradeContextBusy()) Sleep(10);
        

        double ClosePrice = MarketInfo(argSymbol,MODE_ASK);
        bool Closed = OrderClose(argCloseTicket,CloseLots,ClosePrice,argSlippage,Red);
        
        if(Closed < 0)
          {
            int ErrorCode = GetLastError();
            string ErrDesc = ErrorDescription(ErrorCode);
            
            string ErrAlert = StringConcatenate("Close Sell Order - Error: ",ErrorCode,
              ": ",ErrDesc);              
            Alert(ErrAlert);
              
              string ErrLog = StringConcatenate("Ticket: ",argCloseTicket," Ask: ",
                MarketInfo(argSymbol,MODE_ASK));
              Print(ErrLog);
           }
         }
         
       return(Closed);
     }

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3b
bool ClosePendingOrder(string argSymbol, int argCloseTicket)
  {
    OrderSelect(argCloseTicket,SELECT_BY_TICKET);
    
    
    if(OrderCloseTime() == 0)
      {
        while(IsTradeContextBusy()) Sleep(10);        
        bool Deleted = OrderDelete(argCloseTicket,Red);
        
        if(Deleted < 0)
          {
            int ErrorCode = GetLastError();
            string ErrDesc = ErrorDescription(ErrorCode);
            
            string ErrAlert = StringConcatenate("Close Pending Order - Error: ",
              ErrorCode,": ",ErrDesc);              
            Alert(ErrAlert);
              
            string ErrLog = StringConcatenate("Ticket: ",argCloseTicket," Bid: ",
                MarketInfo(argSymbol,MODE_BID)," Ask: ",MarketInfo(argSymbol,MODE_ASK));
            Print(ErrLog);
          }
        }
         
      return(Deleted);
    }
    
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2d v
double CalcBuyStopLoss(string argSymbol, int argStopLoss, double argOpenPrice)
  {
    if(argStopLoss == 0) return(0);
    
    double BuyStopLoss = argOpenPrice - (argStopLoss * PipPoint(argSymbol));
    return(BuyStopLoss);
  }
 

Build 600+

Bool Type

The bool type is intended to store the logical values of true or false, numeric representation of them is 1 or 0, respectively.


Looks like it was that way for old MQL4 too, you might have never had the compiler warning but I suspect the code blocks would never have executed. A point for build 610+ :)

 
REH:
Hi, I have an EA that worked just fine with the meta trader 4 platform.. however I just recently updated to build 610 and now the EA does not work... I compiled it with the new Meta Editor and am now getting two warnings .. Both are the following Expression is always false, Not sure why this would stop the EA from entering trades, but the EA will not enter any trades what so ever ... the problem hi-lighted below is the code -> if(Deleted < 0) and also in another function -> if(Closed < 0) .... always returns false, any suggestions as to why Build 610 sees this differently ? Thanks


A bool type can not be less than 0; rather, it is either true or false (or 1 or 0, respectively).

Consider changing the IF statements to:

if (!Closed) {
   ...
}

if (!Deleted) {
   ...
}

The IF statements would then be executed when Closed is false and when Deleted is false.

 
Thirteen:


A bool type can not be less than 0; rather, it is either true or false (or 1 or 0, respectively).

Consider changing the IF statements to:

The IF statements would then be executed when Closed is false and when Deleted is false.


Not strictly true.

A bool can be any number but will only return false if it is 0. Any other number will return true

    
 bool a =10 * 10;
 bool b =10 * 0-10; 
 Alert( a);  
 Alert( b); 
 
GumRai:


Not strictly true.

A bool can be any number but will only return false if it is 0. Any other number will return true


A matter of semantics I suspect.

A bool can be set by any other number, but the numeric result will always be 1 (or 0)


bool a= 101;

int n = a + 1;

Alert(n); // = 2
 
ydrol:

A matter of semantics I suspect.

A bool can be set by any other number, but the numeric result will always be 1 (or 0)






Good point, argument can be any number, but result will always be 1 or 0.

My apologies Thirteen

 
GumRai: Not strictly true. A bool can be any number but will only return false if it is 0. Any other number will return true
This is strictly true. A bool can be assigned any number, but the resulting bool will ONLY be 0 or 1.
 
WHRoeder:
This is strictly true. A bool can be assigned any number, but the resulting bool will ONLY be 0 or 1.


Did you not see my post, just before yours?

ydrol had already pointed out about the resulting bool value and I agreed and apologised to Thirteen

 

GumRai:

My apologies Thirteen


No apologies necessary. :)

The documentation states that: a "zero value will be interpreted as false, and all other values - as true." Can anyone explain to me why that is? Why isn't it the opposite--a value of 1 will be interpreted as true, and all other values will be interpreted as false? It seems to me (and I certainly can be wrong) that the natural state should be false until it becomes true, rather than true until it becomes false. (Or just maybe I need another coffee with more caffeine!! LOL)

 

Thanks for all your help.... I did change the code to if(!Deleted) and if(!Closed) and recompiled it... This change solved the two warnings I was getting, so now it compiles with no Errors and no Warning, and it loads fine onto the 610 build platform and it allows me to do my manual inputs..... BUT it still does not enter any trades .... the Mystery thickens..... It worked just fine on Build 509 and the Meta Editor for 509 .... I am just learning to program so, I am totaly lost here... I do not have a clue where to look in the code to possibly find why it will not open trades.... THE NEW BUILD SUCKS...... LOL They still obviously have bugs !!!

Any Help would be appreciated.... And thanks for the help you have already given me.. :-)

 
REH:

Thanks for all your help.... I did change the code to if(!Deleted) and if(!Closed) and recompiled it... This change solved the two warnings I was getting, so now it compiles with no Errors and no Warning, and it loads fine onto the 610 build platform and it allows me to do my manual inputs..... BUT it still does not enter any trades .... the Mystery thickens..... It worked just fine on Build 509 and the Meta Editor for 509 .... I am just learning to program so, I am totaly lost here... I do not have a clue where to look in the code to possibly find why it will not open trades.... THE NEW BUILD SUCKS...... LOL They still obviously have bugs !!!

Any Help would be appreciated.... And thanks for the help you have already given me.. :-)

The code posted is for closing order, not to open. So you can post the relevant code if you need help.