How to Use OrderMagicNumber() instead of OrderTicket() for closing the current position?

 

Hello, I wonder if i can use OrderMagicNumber() instead of OrderTicket() for closing the current position?

OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);
return(0);
 
Magic number is not unique. Only the ticket number is unique and identifies the order.
 
Ahmed Abd El Aziz: I wonder if i can use OrderMagicNumber() instead of OrderTicket() for closing the current position?

Of course not.

@William Roeder "Please say something useful or be silent" :)

As requested, live in ignorance. 1 2 3

 
Fernando Carreiro #:
Magic number is not unique. Only the ticket number is unique and identifies the order.

But i can determine a magic number for each position easily and it will be unique too

 
William Roeder #:

Of course not.

As requested, live in ignorance. 1 2 3

You make me laugh :D

 

I found the solution at this function:

int OrderTicketInfo(int Mgic_Number)
{
for(int i = OrdersTotal() - 1; i >= 0 ; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
if(OrderSymbol() == Symbol()
&& OrderMagicNumber() == Mgic_Number)
{
return (OrderTicket());
}
}
return(0);
}
 
Ahmed Abd El Aziz #:But i can determine a magic number for each position easily and it will be unique too

That is not the point. Not every EA is coded by you! Magic numbers are not guaranteed to be unique even if you code your EA as such.