deleting all pending if found one working order - page 2

 
RaptorUK:

Why not . . .

Not tested or tried to compile it . . .

Sneaky! You are going back to the beginning of the loop when you find the valid trade. That is clever.

I would never compare to #define'd symbols with greater than or lesser than. They are symbolic forms and relying on their actual values is poor programming practice. Gain 1 point for sneaky trick and lose two for using greater/lesser comparison on #defined symbols :-)

 
dabbler:

Sneaky! You are going back to the beginning of the loop when you find the valid trade. That is clever, although you would want to use

pos= OrdersTotal()-1; <<<

I would never compare to #define'd symbols with greater than or lesser than. They are symbolic forms and relying on their actual values is poor programming practice. Gain 1 point for sneaky trick and lose two for using greater/lesser comparison on #defined symbols :-)

<<< I wondered about that, wasn't sure if it would then be decremented by the for loop next run through . . . making it OrdersTotal() - 2
 
deVries:


You check in one time not only if there are open buys and/or sells (nOpenOrders)

but also the total with pending include (EAtrades)

Only when nOpenOrders > 0 and when the total trades > nOpenOrders you have to delete the pending

In that case the check is done atonce

If all pending are deleted the next tick this loop for deleting pending will not be done again.....

I think it is faster...

This sort of test takes very little computational effort so I wouldn't bother. I prefer Raptor's solution, not just because it is faster, but also because it removes a lot of duplicated code; time to code and debug is part of the total cost of the EA.
 

Agree nice the coding of RaptorUK fine solution for it.....

 
RaptorUK:
<<< I wondered about that, wasn't sure if it would then be decremented by the for loop next run through . . . making it OrdersTotal() - 2
I<Deleted>
 
       
Eu estava com esse mesmo problema e consequir com esse codigo.



bool fecha_ordem_OP_BUYSTOP_E_OP_BUYLLIMIT(int MAGIC, int slippage_imp, int BuySell = -1 )
  {
   int Total_ordem=0;
   int contador=0;
   int ticket[2000];
   bool res;
   int  error;

   RefreshRates();
   Total_ordem=OrdersTotal();

   for(int j=0;j<Total_ordem; j++)
     {

      if (OrderSelect(j,SELECT_BY_POS,MODE_TRADES)== false)
        break;

      if(( OrderMagicNumber()==MAGIC)&&
         ((OrderType() == BuySell)||(BuySell == -1)) )
        {
            if(OrderSymbol()==Symbol())
            {
              ticket[contador]=OrderTicket();
               contador++;
                Print("contador = ",contador);

            }
        }
     }

   if(IsTradeContextBusy()==true)
      return(false);

   for(int k=contador-1; k>=0; k--)
     {
      RefreshRates();
    //  Print("FECHA TICKET = ",ticket[i]);
      if (OrderSelect(ticket[k],SELECT_BY_TICKET,MODE_TRADES)== false)
        break;
      if (OrderType() == OP_BUYLIMIT) 
 Print("tickt = ", ticket[k]);
         {
           res=    OrderDelete(OrderTicket(),clrNONE);
         }
     }
  return(res);   
 }