# How to select order by magicnumber?

18

Hello,

I would like to assign the EA to order many currency but i don't know how to write.

- I assign magicNo of order "EURUSD" = 835, Then if the EA don't find MagicNo "835" (No order EURUSD). The EA will open order "EURUSD".

- I assign magicNo of order "AUDUSD" = 478, Then if the EA don't find MagicNo "478" (No order AUDUSD). The EA will open order "AUDUSD".

- I assign magicNo of order "EURGBP" = 879, Then if the EA don't find MagicNo "879" (No order EURGBP). The EA will open order "EURGBP".

if(XXX) // OPen order "EURUSD"

{

ticket=OrderSend("EURUSD",OP_SELL,Lots*L1,Bid,3,0,0,"BM_2R_EU",835,0,Green);

if(ticket>0)

{

}

else Print("Error opening BUY order : ",GetLastError());

return(0);

}

if(XXX) // OPen order "AUDUSD"

{

ticket=OrderSend("AUDUSD",OP_SELL,Lots*L1,Bid,3,0,0,"BM_2R_EU",478,0,Green);

if(ticket>0)

{

}

else Print("Error opening BUY order : ",GetLastError());

return(0);

}

if(XXX) // OPen order "EURGBP"

{

ticket=OrderSend("EURGBP",OP_SELL,Lots*L1,Bid,3,0,0,"BM_2R_EU",879,0,Green);

if(ticket>0)

{

}

else Print("Error opening BUY order : ",GetLastError());

return(0);

}

Next>>>>

I would like to write closed order

if(MagicNo==835)  && ((OrderOpenPrice()-OrderClosePrice())/Point)>= TP) then go to closed All order of MagicNo 835

if(MagicNo==478)  && ((OrderOpenPrice()-OrderClosePrice())/Point)>= TP) then go to closed All order of MagicNo 478

if(MagicNo==879)  && ((OrderOpenPrice()-OrderClosePrice())/Point)>= TP) then go to closed All order of MagicNo 879

Thank you

Moderator
6137

```if(OrderMagicNumber()==XXX)
{
// Do Something...
}```

but it has to go after

`OrderSelect()`
not before.
12343

```magic1=0;
magic2=0;
magic3=0;

for (int cnt = 0; cnt < OrdersTotal(); cnt++)
{

if(OrderMagicNumber()==123) magic1++;
if(OrderMagicNumber()==456) magic2++;
if(OrderMagicNumber()==789) magic3++;

}
}

if(magic1<1) ticket=OrderSend( .......

if(magic2<1) ticket=OrderSend( .......

if(magic3<1) ticket=OrderSend( .......```

try this

18

Thank you all,

I wrote counting code in below. So It can bring the value to generate because the EA operate on top first.  T-T

Thank you