int OrderMagicNumber( | ) |
Note: The order must be previously selected by the OrderSelect() function.
if(OrderSelect(10,SELECT_BY_POS)==true)
Print("Magic number for the order 10 ", OrderMagicNumber());
else
Print("OrderSelect returned error of ",GetLastError());
int OrderTicket( | ) |
Note: The order must be previously selected by the OrderSelect() function.
if(OrderSelect(12, SELECT_BY_POS)==true)
order=OrderTicket();
else
Print("OrderSelect failed error code is",GetLastError());
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.
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
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
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.
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.
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.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
What is the difference between OrderMagicNumber and OrderTicket?
Seem the same to me.