- MT4 Magic Number
- OrderMagicNumber
- Order Comment in mql4
From the book:
magic is the magic number of the order. It can be used as the user-defined order identifier. In some cases, it is the only information that helps you to find out about that the order belongs to one or another program that has opened it. The parameter is set by the user; its value can be the same or other than the value of this parameter of other orders.
The thing you might be missing is the fact that multiple experts/scripts can run at the same time on the same account (in a single Terminal or in multiple Terminals), hence u need some way for the expert to label it's orders. Magic is that label.
I understand that it's supposed to serve as a unique identifying number for each order [...]
Just adding to gordon's remarks, and making it even more explicit: the magic number is not typically unique for each order. It's usually unique per EA. For example, you choose an arbitrary value to use for all orders in your EA, or let the user configure one, and you then use the magic number to identify your EA's orders using code such as the following:
for (int i = OrdersTotal() - 1; i >=0; i--) { if (OrderSelect(i, SELECT_BY_POS)) { if (OrderMagicNumber() == <my chosen number>) { // An order created by this EA. // Do something... } else { // Order is manual, or from a different EA } } }
I understand that it's supposed to serve as a unique identifying number for each order
No, it serves as a unique identifier for a whole group of orders, not an individual order. Usually the EA uses only one number for all its orders but a second instance of the same EA (running on a different chart) and also all other EAs would need to use a different number so each instance can find its own orders and will not interfere with other orders in the same account.
In other words: The magic number is not an ID for the orders (this is the ticket number already), its a unique ID for a strategy.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use