Any idea why this boolean statement is returning false?

 

Trying to check if I have active pending orders prior to creating new orders. Sure there is some simple problem here.

Edit: And I should mention that when I run it the EA continues to place orders, one after another. That is why I know it is returning false.

if(activeOrders(OP_SELLSTOP, Symbol(), magicNumber) ==false)
{
      if(min < Bid)
         {
    
            tp = min - tpV;
            sl = mid;
            open = min;
            type = OP_SELLSTOP;
      
            stopPip = (sl - open) / UsePoint;
     
            calcLot = CalcLotSize(EquityPercent, stopPip);
            calcLot = VerifyLotSize(calcLot);
      
            placeOrder(type, min, sl, tp, calcLot, magicNumber);

           
         }  
    
}

//--------------------------------------------------------------------------------
// Ordercheck
//-------------------------------------------------------------------------------- 
bool activeOrders(int type, string argSymbol, int argMagicNumber) 
{
for(int Counter = 0; Counter <= OrdersTotal()-1; Counter++)
      {
        OrderSelect(Counter, SELECT_BY_POS);
        if(OrderMagicNumber() == argMagicNumber && OrderSymbol() == argSymbol)
         {
            if(OrderType() == type)
               {
                  return(true);
               }
            else return(false);
         }             
      }
}

Any ideas?

 
sanders4069:

Trying to check if I have active pending orders prior to creating new orders. Sure there is some simple problem here.

Edit: And I should mention that when I run it the EA continues to place orders, one after another. That is why I know it is returning false.

Any ideas?

try this:

bool activeOrders(int type, string argSymbol, int argMagicNumber) 
{
for(int Counter = 0; Counter <= OrdersTotal()-1; Counter++)
      {
        OrderSelect(Counter, SELECT_BY_POS);
        if(OrderMagicNumber() == argMagicNumber && OrderSymbol() == argSymbol)
         {
            if(OrderType() == type)
               {
                  return(true);
               }
            
         }             
      }
return(false);
}
 
Dingetje:

try this:


Wow. Guess that did it, thanks for taking a look.
 
  1. Always test return codes (OrderSelect)
    bool activeOrders(int type, string argSymbol, int argMagicNumber) 
    {
       for(int Counter = OrdersTotal()-1; Counter >= 0; Counter--) if(
          OrderSelect(Counter, SELECT_BY_POS)
       && OrderMagicNumber() == argMagicNumber 
       && OrderSymbol()      == argSymbol
       && OrderType()        == type) return(true);
       return(false);
    }
    
  2. Always count down in the presence of multiple orders (multiple charts or multiple EAs)
  3. if(activeOrders(OP_SELLSTOP, Symbol(), magicNumber) ==false)
    You may want to test OP_SELL as well - Once the sell stop opens it becomes a sell.
 
WHRoeder:
  1. Always test return codes (OrderSelect)
  2. Always count down in the presence of multiple orders (multiple charts or multiple EAs)
  3. You may want to test OP_SELL as well - Once the sell stop opens it becomes a sell.

Thank you so much for the reply, I am always looking for ways to improve my code.