Plese help me with EA programming

 

Hi

I have a problem with EA. I have wrote a program in EA. This is work in 3 currencies. Now my problem is here When 3 order are open (for example : EURUSD, EURJPY & USDJPY) and I wanna to close one of them (for example : EURUSD) How can I select this order to close and what is the command?

Your help is appreciated.

 
ashkan1115 wrote >>

Hi

I have a problem with EA. I have wrote a program in EA. This is work in 3 currencies. Now my problem is here When 3 order are open (for example : EURUSD, EURJPY & USDJPY) and I wanna to close one of them (for example : EURUSD) How can I select this order to close and what is the command?

Your help is appreciated.

Just use OrderClose after OrderSelect() with Symbol() and Magic() check.

 
ashkan1115:

Hi

I have a problem with EA. I have wrote a program in EA. This is work in 3 currencies. Now my problem is here When 3 order are open (for example : EURUSD, EURJPY & USDJPY) and I wanna to close one of them (for example : EURUSD) How can I select this order to close and what is the command?

Your help is appreciated.

Here you are:

int CloseOrders(int magicnr)
   {
   int total=OrdersTotal();
   for (int cnt=total-1;cnt>=0;cnt--)
   {
      OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      if (OrderMagicNumber()==magicnr && OrderSymbol()=="EURUSD")
      {
         if (OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),1);
         if (OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),1);
      }
   }
   return(0);
   }
Cheers
 

Remember to use a unique magic number for each chart, then the close function here will work. By the way, using this technique will allow you to run your automation on as many charts as you want, regardless of the pair. I have one that is currently demo trading across 22 pairs.

Reason: