Download MetaTrader 5

How to select order by magicnumber?

To add comments, please log in or register
Pars1985
18
Pars1985 2016.03.10 10:03 

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)

           {

            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) sendEmail();

           }

         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)

           {

            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) sendEmail();

           }

         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)

           {

            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) sendEmail();

           }

         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

Marco vd Heijden
Moderator
4733
Marco vd Heijden 2016.03.10 11:44  
if(OrderMagicNumber()==XXX)
 {
  // Do Something...
 }

but it has to go after

OrderSelect()
not before.
Siti Latifah
6897
Siti Latifah 2016.03.10 13:04  
magic1=0;
magic2=0;
magic3=0;

for (int cnt = 0; cnt < OrdersTotal(); cnt++)
      {
      if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)){

        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

Pars1985
18
Pars1985 2016.03.11 04:57  

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 

To add comments, please log in or register