What is the difference between OrderMagicNumber and OrderTicket?

 

What is the difference between OrderMagicNumber and OrderTicket?

Seem the same to me.

 
int OrderMagicNumber( )
Returns an identifying (magic) number for the currently selected order.
Note: The order must be previously selected by the OrderSelect() function.
Sample:
  if(OrderSelect(10,SELECT_BY_POS)==true)
Print("Magic number for the order 10 ", OrderMagicNumber());
else
Print("OrderSelect returned error of ",GetLastError());





int OrderTicket( )
Returns ticket number for the currently selected order.
Note: The order must be previously selected by the OrderSelect() function.
Sample:
  if(OrderSelect(12, SELECT_BY_POS)==true)
order=OrderTicket();
else
Print("OrderSelect failed error code is",GetLastError());
 
SanMiguel:

What is the difference between OrderMagicNumber and OrderTicket?

Seem the same to me.

This question comes up a lot. For example, see 'What is and how to set the magic number at EA's ?'


Putting it very simply: the ticket is a unique identifier for each order, allocated by the broker. The magic number is defined by you. Typically, you don't give each order a unique magic number. Instead, you give all the orders from a particular instance of an EA the same magic number, so that the EA can then detect which orders it has created, versus orders created manually or by another EA.

 
jjc:

This question comes up a lot. For example, see 'What is and how to set the magic number at EA's ?'


Putting it very simply: the ticket is a unique identifier for each order, allocated by the broker. The magic number is defined by you. Typically, you don't give each order a unique magic number. Instead, you give all the orders from a particular instance of an EA the same magic number, so that the EA can then detect which orders it has created, versus orders created manually or by another EA.

How long is the magic number remembered for - just until the program remains open?

How could I propogate the variable so that each time I turn the program on it is still there, eg: https://forum.mql4.com/21340#157338

 
SanMiguel wrote >>

How long is the magic number remembered for - just until the program remains open?

How could I propogate the variable so that each time I turn the program on it is still there, eg: https://forum.mql4.com/21340#157338

The Magic Number is attached to the order. So it exists as long as the order does.

- Tovan

 
tovan:

The Magic Number is attached to the order. So it exists as long as the order does.

- Tovan

But it's not stored on the server?

Can you give an order a magic number after it has been sent, ie when modifying it?

I open manual trades but I want an EA to close them and remember which it has alreday closed by half so it doesn't touch them again.

 
SanMiguel wrote >>

But it's not stored on the server?

Can you give an order a magic number after it has been sent, ie when modifying it?

I open manual trades but I want an EA to close them and remember which it has alreday closed by half so it doesn't touch them again.

Yes, the Magic Number is stored on the server. And no, I don't believe that you can change it once the order is sent. You could write a script to place your order - inserting the Magic Number in OrderSend.

 
tovan wrote >>

Yes, the Magic Number is stored on the server. And no, I don't believe that you can change it once the order is sent. You could write a script to place your order - inserting the Magic Number in OrderSend.

How do we generate a unique magic order number each time?

1. So I create an order through a script assigning a magic number.

2. Half the trade is closed at a certain point.

3. A new ticket number is created with half the lot, but the same magic number.

4. I can now search the history for the magic number and leave this new half lot alone.

Reason: