Why Magic Number??

 
Can someone please explain to me what the purpose of using a "magic number" is? I understand that it's supposed to serve as a unique identifying number for each order but isn't that same function served by a ticket number? Why make up your own..just call by ticket number. I know Im missing the point here, please enlighten me. Thanks!
 
It is the unique identifier for the expert advisor. That way the expert advisor will not close an order (or modify) that is opened manually or by another expert advisor.
 

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.

 
supertrade:
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 
      }
   }
}
 
It's for grouping a kind of trades.
 
supertrade:
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.

 
Ah!! I get it! Thanks!!