How to limit EA to open only one position in specific currency pair

 

Hello,

Does anyone have code for this? By searching google in previous topics I found something like this but it doesn't seem to work:

for (int k = 0; k < OrdersTotal(); k --) 
   {
      OrderSelect(k, SELECT_BY_POS, MODE_TRADES);
      if(OrderType() <= OP_SELL &&  OrderSymbol() == Symbol()) 
      {
        if(OrderType() == OP_BUY) 
         {   


Best regards,

Roberts

 
Franko: like this but it doesn't seem to work:
for (int k = 0; k < OrdersTotal(); k --){
  OrderSelect(k, SELECT_BY_POS);
  1. Of course it doesn't work. You start at zero, check for going too high, and then go lower.
  2. What are Function return values ? How do I use them ? - MQL4 forum
  3. Count first and then decide. See https://www.mql5.com/en/forum/145507