While one currency has a trade or trades, the others musn't have trades by EA.

 

Hi all,

I have an EA. It runs on 5 currencies (eurusd, gbpusd, usdchf, usdcad, and, audusd).

When the EA has a trade or sometimes trades on a currency forexample on eurusd, it must not open trades on the other currencies.

How can I code that?

Best.


Or,

How can I manage total trades for above currencies. Forexample, I want to allow max. 6 trades at the same time in totally (for all currencies).

 

Use the same magic number for all instances of the EA and check if there is already an open trade with the magic number.

Or

Count the number of open trades with the same magic number and don't open any more if the maximum has been reached.

 
I can count for a currency  by using following code;

int Trade::Count(int type)
  {
   int count=0;
   for(int i=0; i<=OrdersTotal()-1; i++)
     {
      bool Select=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(Select && OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber && OrderType()==type) count++;
     }
   return (count);
}


However, this code for a currency. not for total currencies.

 
int Trade::CountTotal()
  {
   int count=0;
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      bool selected=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(selected && OrderMagicNumber()==MagicNumber) count++;
     }
   return (count);
  }
This counts all open orders belonging to this EA. So before opening a new order the EA could check whether this count has reached a limit (MaxOpenTrades or so.)
 
lippmaje:
This counts all open orders belonging to this EA. So before opening a new order the EA could check whether this count has reached a limit (MaxOpenTrades or so.)

Thank you so much!

 
This was interesting. I will definitely try it. :-)
Reason: