Multi-Symbol EA - How do I open only one trade at a time?

 

Hey all,


I have written the following code to check if there is an open order with a matching symbol and magic number within my multi-symbol EA, but it does not prevent multiple orders from opening.

The OpenTradeOrderTicket is a global array that is meant to store a 1 or 0 depending on whether there is an open order on the current symbol in the loop but doesn't.

I tried to debug with the Print's that you can see but they do not print anything which leads me to believe the loop is not even running for some reason.

Any advice is greatly appreciated.


      ulong ticket;
      string symbol;
      long order_magic; 
      
      uint total = OrdersTotal();
      for(uint i=0 ; i < total ; i++)
      {
         if((ticket=OrderGetTicket(i))>0)
         {
            symbol        = OrderGetString(ORDER_SYMBOL);
            order_magic   = OrderGetInteger(ORDER_MAGIC);
            
            Print("Order Magic ", order_magic);
            Print("Order Symbol ", symbol);
            Print("Loop Symbol ", CurrentSymbol);
            Print("Magic Number", Magic_No);
            
            
            if(symbol == CurrentSymbol && order_magic == Magic_No) OpenTradeOrderTicket[SymbolLoop] = 1; else OpenTradeOrderTicket[SymbolLoop] = 0;
         }
      }
 
  1.       uint total = OrdersTotal();
          for(uint i=0 ; i < total ; i++){
             if((ticket=OrderGetTicket(i))>0)
             {
                symbol        = OrderGetString(ORDER_SYMBOL);
                order_magic   = OrderGetInteger(ORDER_MAGIC);
    There are no such functions in MT4.

    Why did you post your MT5 question in the MQL4 section, (bottom of the Root page) instead of the MT5 General section?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  2. Once a pending order opens, it is not an order, it is a position.
    MT5: first select a position via CPositionInfo, directly, or by 'MT4Orders' library (2016)
Reason: