problem...not yet to finish delete the order!!! above script to take it???

 
Hi...

coming again need help and ask some question..

the scripts net yet finish delete the order, above script to execute!!
how can do the scripts wait to finish and turn the next return above?

example stoplevel=5, sell sellstoptotals 5 drop 1 to execute to delete sellstop, selllimit and buystop, problem buystop not yet to finish delete, above script to take it??

thanks

egt520
if(stoplevel > buystoptotals && 0 < buystoptotals + buylimittotals + selllimittotals)
{
         CleanAllPendings(magic,4); //delete BuyStop order
         CleanAllPendings(magic,2); //delete BuyLimit order
         CleanAllPendings(magic,5); //delete SellStop order
}
 
if(stoplevel > sellstoptotals && 0 < sellstoptotals + selllimittotals + buylimittotals)
{
         CleanAllPendings(magic,5); //delete SellStop order
         CleanAllPendings(magic,3); //delete SellLimit order
         CleanAllPendings(magic,4); //delete BuyStop order
}
 
void CleanAllPendings(int magic,int cmd)
{  
    for(int i=OrdersTotal()-1;i>=0;i--)
    {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if ( OrderSymbol() != Symbol()) continue;
      if ( OrderMagicNumber() != magic) continue;
      if ( OrderType() != cmd) continue;
 
      int ticket = OrderDelete(OrderTicket(),CLR_NONE);
    }
    return(ticket);
}
Reason: