Download MetaTrader 5

Confusion reigns supreme

To add comments, please log in or register
xanderhinds
108
xanderhinds  
bool MySelect(int iWhat, int eSelect, int ePool=MODE_TRADES) // MySelect bool initiation, value given below
// so I'm thinking to add in a myselect function for Buy and one for Sell.. as i simply dont understand 'return(OrderType() <= OP_SELL);'  
{

   if(!OrderSelect(iWhat, eSelect, ePool) )  return (false);
   if(OrderMagicNumber() != magicnumber   )  return (false); // OMN = OMN ELSE MySelect = FALSE
   if(OrderSymbol()      != symbolchart   )  return (false); // OrderSymbol = SYMBOL
   if(ePool != MODE_HISTORY               )  return (true ); // order selected is not closed / from history
   return(OrderType() <= OP_SELL);  
  
}

So I was forwarded to this piece of code that I'm currently trying to understand.. can anyone tell me why 


   return(OrderType() <= OP_SELL);  

Is there?

Alain Verleyen
Moderator
29908
Alain Verleyen  
Please don't create a new topic, just continue with your existing one.
xanderhinds
108
xanderhinds  
Would 
bool MySelect(int iWhat, int eSelect, int ePool=MODE_TRADES) // MySelect bool initiation, value given below
// so I'm thinking to add in a myselect function for Buy and one for Sell.. as i simply dont understand 'return(OrderType() <= OP_SELL);'  
{

   if(!OrderSelect(iWhat, eSelect, ePool) )  return (false);
   if(OrderMagicNumber() != magicnumber   )  return (false); // OMN = OMN ELSE MySelect = FALSE
   if(OrderSymbol()      != symbolchart   )  return (false); // OrderSymbol = SYMBOL
   if(ePool != MODE_HISTORY               )  return (true ); // order selected is not closed / from history  
   if(OrderType() != OP_BUY)  return(OrderType() == OP_SELL);
   else return(OrderType() == OP_BUY);
}

not make more sense?

Carl Schreiber
Moderator
7964
Carl Schreiber  
As you can assign a boolean test to a variable like bool a = x >= y; a function can as well return a boolean test without assigning it to variable right before.
whroeder1
17125
whroeder1  
xanderhinds: Would not make more sense?
Had you seen the original https://www.mql5.com/en/forum/143514#comment_3626889 The comment on  type <= sell explains why it's not just return true.
if(OrderType() != OP_BUY)  return(OrderType() == OP_SELL);
else return(OrderType() == OP_BUY);

// equivalent

return OrderType() == OP_BUY || OrderType() == OP_SELL;

// And since buy=0 and sell = 1 and there are no negatives

return OrderType() <= OP_SELL;
To add comments, please log in or register