Ticket changes after OrderSend

 

Hello,

I have a big Problem using the received Ticket number of OrderSend function.

The Ticket which I get back from the function is not the same as the ticket that is placed in the Open Trades List.....

Has anyone an Idea how this is possible??


The reason why I need the right ticket is because of I need to modify the order after sending it to place a StopLoss.

My Broker is XTB.

Is there anyone who had the same problem??


Thanks for you help!

 
Show your code.
 
gordon:
Show your code.

int ticket = OrderSend(Symbol(), OP_BUY, 1, Ask,10,0, 0);
int err = GetLastError();
Print("Ticket send: " + ticket);

if(err == 0)
{
int tries = 3;
while(tries > 0)
{
double stop = Ask-(20*Point);
stop = NormalizeDouble(stop, Digits);

if(OrderModify(ticket, 0, stop, 0, 0) == FALSE)
{
int err1 = GetLastError();
Print("Error: " + err1);
}
else break;

tries--;
}

}


The Error which I get from OrderModify is "unknown ticket" and when I take a look to the OpenTrades, the ticket of the open order is not the same number as I got back from OrderSend().


Have you got any idea?


Thanks!

 
int ticket = OrderSend(Symbol(), OP_BUY, 1, Ask,10,0, 0);
int err = GetLastError();
Print("Ticket send: " + ticket);

if(err == 0)
{
  int tries = 3;
  while(tries > 0)
  {
    double stop = Ask-(20*Point);
    stop = NormalizeDouble(stop, Digits);

    if(OrderModify(ticket, 0, stop, 0, 0) == FALSE)
    {
      int err1 = GetLastError();
      Print("Error: " + err1);
    }
    else break;

    tries--;
  }
}


Dangerous code, what if your 3 retys fail? letting Trade run without SL/TP?


but your OrderModify should look like:

OrderModify(ticket, OrderOpenPrice(), stop, 0, 0)

Also note that on a five digits broker your stop will be 2pips, on most of pairs that distance is not allowed.

There are so many topics on that, i don't think it will be hard to find one-...

 
zzuegg:

Dangerous code, what if your 3 retys fail? letting Trade run without SL/TP?




this is only a test code beacuse of my ticket problem.

My EA code is a little bit more secure :)

 
i edited the post above, i don't think that the ticket is your problem..
 
zzuegg:

Dangerous code, what if your 3 retys fail? letting Trade run without SL/TP?


but your OrderModify should look like:

Also note that on a five digits broker your stop will be 2pips, on most of pairs that distance is not allowed.

There are so many topics on that, i don't think it will be hard to find one-...





Okay as I sayd this is only a test code for me but It is working if I decrement the received ticket by 1.

Then I have in most cases the ticket number which is really assigned to the Trade.

 

You need to select the order before you can modify it. Try OrderSelect(ticket,SELECT_BY_TICKET) before the OrderModify.

 
kennyhubbard:

You need to select the order before you can modify it. Try OrderSelect(ticket,SELECT_BY_TICKET) before the OrderModify.


The above code is working as it is but only if I change the received ticket from OrderSend that it is the same ticket as it is really in my open trades

 
MQL4Beginner:

The above code is working as it is but only if I change the received ticket from OrderSend that it is the same ticket as it is really in my open trades


Okay I have a few new details. for a short time I can see the order with the ticket i received in the TradeList. But the first Open trade is removed after a few seconds and only the order with the wrong ID remains in the List!!


Any Idea??
 

Thanks for the fast answers!

I am now trying all of your ideas:

It doesn't matter when I use OrderOpenPrice() as a price for Order modify. I still get the same error.

I also tried to select the order directly after OrderSend but still the same error.

Then I changed my OrderModify to:

OrderModify(OrderTicket(), OrderOpenPrice(), stop, 0, 0)

But I still get "Unknown Symbol" error.


Have you got any Ideas and why I get 2 Orders in the first seconds and the first will be deleted after a few seconds??

Is it possible that a market open order is first placed as pending Order and the moved to another Open Trade??

Reason: