OrderSelect doesn't wortk

 

Hi, I'm trying to get ticket number after sending an order 

 int ticket=OrderSend(Symbol(),OP_BUY,volume,Ask,3,stoploss,takeprofit,"My order",0,0,clrGreen);
     if(ticket<0)
     {
        Print("OrderSend failed with error #",GetLastError());
     }
        else{
     Print(OrderSelect(ticket, SELECT_BY_POS));
     if(OrderSelect(ticket, SELECT_BY_POS)==true){
         Print("order ticket : ", OrderTicket());
         ticket=OrderTicket();
     }
     }
                        

but 

OrderSelect

 always returns false

what's the problem?

 
  1. How To Ask Questions The Smart Way. (2004)
              Don't rush to claim that you have found a bug.
    Questions Not To Ask
              My program doesn't work. I think system facility X is broken.

    It is almost always your code.

  2. if(OrderSelect(ticket, SELECT_BY_POS)==true){

    A ticket number is not a position index.

  3. You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled where as Long_Entry sounds like a trigger price or a ticket number and “if long entry” is an incomplete sentence.

 
JAVAD SHEIKH:

Hi, I'm trying to get ticket number after sending an order 

but 

 always returns false

what's the problem?

The best thing to do is implement the following:

if(!OrderSelect(ticket, SELECT_BY_POS){

        Print("Order Select Error "+IntegerToString(GetLastError(),0));

}

then you will return an error code and you should be able to diagnose the problem with MQL4's list of Error Codes. I also tend to make this a MessageBox() function as well as a print function, so it's immediately obvious if there is a problem.  

Also, you don't need the ''== true". The OrderSelect() is a bool function by default, so you don't need to further clarify if the function returns true or false. :)

 
Todd Peter Gilbey #: The best thing to do is implement the following:
if(!OrderSelect(ticket, SELECT_BY_POS){

No, the best thing is stop selecting by position with a ticket number.