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

To add comments, please log in or register
Murat Yazici
1403
Murat Yazici  

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).

Keith Watford
Moderator
16114
Keith Watford  

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.

Murat Yazici
1403
Murat Yazici  
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.

lippmaje
417
lippmaje  
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.)
Murat Yazici
1403
Murat Yazici  
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!

Rekhit Pachanekar
11
Rekhit Pachanekar  
This was interesting. I will definitely try it. :-)
To add comments, please log in or register