Why my OrderSend Function does not return the order ticket number?

 

Hi There,

As the documentation says, the OrderSend function:

Ord Returns number of the ticket assigned to the order by the trade server or -1 if it fails.

It should return the recent opened ticket number right?
But it always return 0 for me...

Here is my code:

int ticket=OrderSend(Symbol(),OP_BUY,1,Ask,5,0,0,NULL,12345,0,clrBlue);

When I try to refer to the order, I try using "ticket"(OrderSelect(ticket,SELECT_BY_TICKET)). But it is always 0. I figured it out by using Comment function in start();

What is my misunderstanding?
Your Advice is appreciated.

Documentation on MQL5: Trade Functions / OrderSend
Documentation on MQL5: Trade Functions / OrderSend
  • www.mql5.com
[in,out]  Pointer to a structure of MqlTradeResult type describing the result of trade operation in case of a successful completion (if true is returned). parameter are filled out correctly. If there are no errors, the server accepts the order for further processing. If the order is successfully accepted by the trade server, the OrderSend...
 

When I try to refer to the order, I try using "ticket"(OrderSelect(ticket,SELECT_BY_TICKET)).

What is that supposed to do??

 
  1. int ticket=OrderSend(Symbol(),OP_BUY,1,Ask,5,0,0,NULL,12345,0,clrBlue);

    Check your return codes, and report your errors (including market prices and your variables). Don't look at GLE/LE unless you have an error. Don't just silence the compiler (strict), it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum 2012.05.20
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles 25 March 2014

  2. HosseinKOGO: But it is always 0. What is my misunderstanding?
    OrderSelect does not return an int.

  3. If the OrderSend failed, you don't have a valid ticket to select.

  4. Always post all relevant code.
         How To Ask Questions The Smart Way. 2004
              Be precise and informative about your problem

 
Keith Watford:

When I try to refer to the order, I try using "ticket"(OrderSelect(ticket,SELECT_BY_TICKET)).

What is that supposed to do??

I mean I use

if(OrderSelect(ticket,SELECT_BY_TICKET)==true)


to just select the recent opened order. Which

ticket = OrderSend(...);
and when I comment(ticket), it is "0"
 

Are you sure about that ? 

Because last time i checked, OrderSend() returns number of the ticket assigned to the order by the trade server or -1 if it fails. 

So it's either the ticket number, or -1 and not 0.

Maybe its a good idea if you post the complete code.

 
William Roeder:
  1. Check your return codes, and report your errors (including market prices and your variables). Don't look at GLE/LE unless you have an error. Don't just silence the compiler (strict), it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum 2012.05.20
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles 25 March 2014

  2. OrderSelect does not return an int.

  3. If the OrderSend failed, you don't have a valid ticket to select.

  4. Always post all relevant code.
         How To Ask Questions The Smart Way. 2004
              Be precise and informative about your problem

Sorry I mislead you, I mean when I use

if(OrderSelect(ticket,SELECT_BY_TICKET)==true) ...


it does not select the last recent opened order however

ticket= OrderSend(...);


- The OrderSend() is successful since it draw object in visual mode and really opens an order.

I have tried to make it shorter to take less time of you, but here is my original code and thank you for your time:

int Buys()
{
   BuyTicket[x]=OrderSend(Symbol(),OP_BUY,LotSize*BuyZarib,Ask,Slippage,0,0,NULL,MagicA,0,clrBlue);

   if(BuyTicket[x]>=0)
   {
      x++;
      return(0);
   }
return(0);
}

And I defined 

int BuyTicket[100];

in global area to support up to 100 buy orders.

I defined x in global area as int also

 
Marco vd Heijden:

Are you sure about that ? 

Because last time i checked, OrderSend() returns number of the ticket assigned to the order by the trade server or -1 if it fails. 

So it's either the ticket number, or -1 and not 0.

Maybe its a good idea if you post the complete code.

Maybe it is because of my defined array? Please take a look on my recent reply.
 

Are you saying that,

int Buys()
{
   BuyTicket[x]=OrderSend(Symbol(),OP_BUY,LotSize*BuyZarib,Ask,Slippage,0,0,NULL,MagicA,0,clrBlue);
   
   Print(BuyTicket[x]);    

   if(BuyTicket[x]>=0)
   {
      x++;
      return(0);
   }
return(0);
}

This prints out 0 ? 

 
Marco vd Heijden:

Are you saying that,

This prints out 0 ? 

No I put Comment func in my Start func.
you pointed right to my problem. When I put my Comment in Buys(), it has value. But why its value is 0 when I put it in Start()?

 

Maybe because of this

return(0);
And otherwise, again maybe its a good idea to post the complete code.
 
Marco vd Heijden:

Maybe because of this

And otherwise, again maybe its a good idea to post the complete code.

I got it!
Thank you for your pointing. The reason is: when BuyTicket[x] have last order ticket, it increases x by 1 so in start function when I Comment(BuyTicket[x]), It is actually BuyTicket[x+1] which logically has no value.

Again thanks to all people engaged in my problem.

Reason: