One EA - two independent magic number trades

 

Hi Guys,


how can I code an EA that can trade 4 pairs, but each two pairs were traded with a specific magic number in one EA.

EA:

1.) buy EURUSD / sell GBPUSD <-- both pairs get magic number 1234

2.) buy EURUSD / sell USDCHF <-- both pairs get magic number 5678


So EA check for both magic number:

- open positions

- profit of open positions

- close that pairs with that magic number which are in given profit


Who can help me?


Best regards,

 

Hi,

Step one: detect Symbol() & Magic Number:

int CountSym(string sym)  {

   int count=0;
   int i;
   int total=OrdersTotal();
   for(i=0;i<total;i++)
   {
   OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
 
   if(OrderSymbol()!= sym) continue;
   if(OrderMagicNumber() != Magic) continue;
 
   count++;
   }
   return(count);
}

Step two: CAll the Order function with sub function:

if(CountSym(sym)>0) OrdersList(); // Orders section with TS, BE and more.
else { 
//OrderSend function BUY or SELL with specific magic
}

S.T

 
    for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
        OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
    && (OrderMagicNumber()  == magic.number1            // my magic number
      ||OrderMagicNumber()  == magic.number2)
    &&  OrderSymbol()       == Symbol() ){              // and my pair.
 
 
  1. jimbofx7:
    On which position I have to put in the code?
    No Slaves here, learn to code or pay someone. We're not going to code it FOR you. We are willing to HELP you.
Reason: