English

## Searching for opened orders my magic number

 Moderator3406 GumRai 2015.11.30 12:46 #   ```int AreThereOrders ()  //Why use an int, the function is a true false question { if (OrdersTotal()<1) { return 1; } else if (OrdersTotal()>0)  //No need for the else as you have alreaddy returned if OT is less than 1 { int i; for (i=OrdersTotal()-1; i>=0; i--)    {    if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))    continue;    if( OrderMagicNumber()!= magic && OrderSymbol()!=Symbol()) //This means that if  any order is open that does not have    {                                                          //the magic number or chart symbol, a new order is opened    return 2;    }      }        }    return 0 ;      }```more sensible, in my opinion```bool AreThereOrders()   {    if(OrdersTotal()<1)      {       return (false);      }    int i;    for(i=OrdersTotal()-1; i>=0; i--)      {       if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))          continue;       if(OrderMagicNumber()==magic && OrderSymbol()==Symbol())         {          return (true);         }      }    return (false);   }``` Then instead of``` if (AreThereOrders() == 1 || AreThereOrders() ==2)      {       //buy or sell condition      }``` use``` if (!AreThereOrders())      {       //buy or sell condition      }``` more logical.
 Moderator3406 GumRai 2015.11.30 13:28 #   Stan4o1: What i meant is that i want to open orders in 2 cases - if,  no order is open, and if there is already an open order, but it has to be from another EA, so that my new order will be the only order for the specified currency . My idea is to have only 1 order per EA / currency/, so that why i `ve written if the magic number doesn`t match it can open a new order/ because it will be from another EA/ and i will have only 1 per currency. But the problem is that it doesn`t open only 1 order for the currency. Maybe before i didnt explain it very well.  and that is precisely what```      if(OrderMagicNumber()==magic && OrderSymbol()==Symbol())         {          return (true);         }``` achieves