Close pending orders

 
Would anybody be so kind as to look at my close pending order code... It works fine but does return "return value of 'OrderDelete' should be checked" when compiled. Just want to clean it up if I can. Thanks in advance.
int delorderbuystop()
 {
  int i;
   for(i=0;i<TotalOpenBuyOrders();i++)
   {
    if(OrderSelect(i, SELECT_BY_POS)==true)
       //OP_BUYSTOP     4       Buy stop pending position.
       //OP_SELLSTOP    5       Sell stop pending position.
        if(OrderType()==OP_BUYSTOP)
 {
OrderDelete(OrderTicket());
return(true);
}
}
return(false);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

int delordersellstop()
 {
  int i;
   for(i=0;i<TotalOpenSellOrders();i++)
   {
    if(OrderSelect(i, SELECT_BY_POS)==true)
       //OP_BUYSTOP     4       Buy stop pending position.
       //OP_SELLSTOP    5       Sell stop pending position.
        if(OrderType()==OP_SELLSTOP)
 {
OrderDelete(OrderTicket());
return(true);
}
}
return(false);
} 
 
  1. Adam Woods "return value of 'OrderDelete' should be checked"

    So check it! What's unclear? 

    Check your return codes for errors, and report them including GLE/LE, your variable values, and the market. That way we would know that at least you are calling your code.
              What are Function return values ? How do I use them ? - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

    Don't look at GLE/LE unless you have an error. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

  2.    for(i=0;i<TotalOpenSellOrders();i++) if(
          OrderSelect(i, SELECT_BY_POS)
       && OrderType()==OP_SELLSTOP
       ){
         OrderDelete(OrderTicket());
         return(true);

    Why are you returning? Don't you want to delete all of them?

  3. TotalOpenSellOrders is a count, not a position. Suppose you have two buys at position zero and one and a SellStop at two. Your loop goes from [0…1] and closes nothing.

  4. Magic number only allows an EA to identify its trades from all others. Using OrdersTotal/OrdersHistoryTotal (MT4) or PositionsTotal (MT5), directly and/or no Magic number filtering on your OrderSelect / Position select loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum
              PositionClose is not working - MQL5 programming forum
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles

  5. In the presence of multiple orders (one EA multiple charts, multiple EAs, manual trading,) while you are waiting for the current operation (closing, deleting, modifying) to complete, any number of other operations on other orders could have concurrently happened and changed the position indexing:

    1. For non-FIFO (non-US brokers), (or the EA only opens one order per symbol,) you can simply count down, in a position loop, and you won't miss orders. Get in the habit of always counting down.
                Loops and Closing or Deleting Orders - MQL4 programming forum
      For In First Out (FIFO rules — US brokers,) and you (potentially) process multiple orders per symbol, you must find the earliest order (count up,) close it, and on a successful operation, reprocess all positions.
                CloseOrders by FIFO Rules - Strategy Tester - MQL4 programming forum - Page 2 #16
                MetaTrader 5 platform beta build 2155: MQL5 scope, global Strategy Tester and built-in Virtual Hosting updates - Best Expert Advisors - General - MQL5 programming forum #1 № 11 ACCOUNT_FIFO_CLOSE

    2. and check OrderSelect in case earlier positions were deleted.
                What are Function return values ? How do I use them ? - MQL4 programming forum
                Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    3. and if you (potentially) process multiple orders, must call RefreshRates() after server calls if you want to use, on the next order / server call, the Predefined Variables (Bid/Ask) or (be direction independent and use) OrderClosePrice().
 
Thanks for the direction finally got it
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

int delorderbuystop()
 {
      for(int i = 0;i < OrdersTotal(); i++)
      {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
            if(OrderSymbol() == Symbol())
               if(OrderType()==OP_BUYSTOP)
            {
               int ticket = OrderTicket();
               if(!OrderDelete(ticket))
                  Print(GetLastError());         
               else 
                  i--;
            }
      }
    return(OrderTicket());
    
   }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

int delordersellstop()
 {
      for(int i = 0;i < OrdersTotal(); i++)
      {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
            if(OrderSymbol() == Symbol())
               if(OrderType()==OP_SELLSTOP)
            {
               int ticket = OrderTicket();
               if(!OrderDelete(ticket))
                  Print(GetLastError());         
               else 
                  i--;
            }
      }
    return(OrderTicket());
    
   }
 
Adam Woods: Thanks for the direction finally got it

No you didn't; ignored #1.5.1 Paragraphs one or two.