Select By Magic Number ?

 
I want to select order by magic number, as I have different orders on different pairs and different magic number on the same pair ( symbol ), in total I have 4 magic number on the same currency and I am trading 3 currency pairs
Can I select orders by magic number ?

What I want to do is that:
if order with magic number 111 has a 20 pips DD and order with magic number 333 has 22 pips in profit I want to close both orders. Is this possible ?
 

Can I select orders by magic number ?

No, you select orders by Ticket Number or position in the trade pool. Then, examine the order to see if it meets other criteria.

 

As Phy said, you loop through the Orders Collection, look at each one & do stuff accordingly.

The function below just counts the open orders for Symbol & MagicNumber - you could adapt it for OrderClose

Good Luck

-BB-


int ActiveTradesForMagicNumber(string SymbolToCheck, int MagicNumberToCheck)
{
int icnt, itotal, retval;
retval=0;
itotal=OrdersTotal();
   for(icnt=0;icnt<itotal;icnt++)
     {
      OrderSelect(icnt, SELECT_BY_POS, MODE_TRADES);
       // check for opened position, symbol & MagicNumber
      if(OrderType()<=OP_SELL && OrderSymbol()==SymbolToCheck  && OrderMagicNumber()==MagicNumberToCheck) 
        {
       
        retval++;
       
        //Print("Orders opened : ",retval);
       
        }
     }
return(retval);
}
Reason: