Delete Pending Order Error

 
I want to delete a pending order at specified time, but always getting error in MetaEditor5

//+------------------------------------------------------------------+
//| Delete all pending orders at the specified time                  |
//+------------------------------------------------------------------+
void DeletePendingOrders()
  {
   for (int i = OrdersTotal() - 1; i >= 0; i--)
     {
      if (OrderSelect(i,SELECT_BY_POS))
        {
         int orderType = (int)OrderGetInteger(ORDER_TYPE);
         if (orderType == ORDER_TYPE_BUY_STOP || orderType == ORDER_TYPE_SELL_STOP)
           {
            ulong ticket = OrderGetTicket();
            if (!trade.OrderDelete(ticket))
              {
               Print("Error deleting pending order: ", GetLastError());
              }
            else
              {
               Print("Pending order deleted: ", ticket);
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+

Error: 
'SELECT_BY_POS' - undeclared identifier
'OrderSelect' - wrong parameters count
'OrderGetTicket' - wrong parameters count


 

please edit your post -

--------------------------

When you post code please use the CODE button (Alt-S)!

Use the CODE button

 
  1. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
          General rules and best pratices of the Forum. - General - MQL5 programming forum #25 (2019)
              Messages Editor
          Forum rules and recommendations - General - MQL5 programming forum (2023)

  2. You know what the problem is, now read the documentation and learn MT5. Your posted code is mostly MT4.

  3. There is no need to create pending orders in code.

    1. The pending has the slight advantage, A) you are closer to the top of the queue (filled quicker), B) there's no round trip network delay (filled quicker.)

      Don't worry about it unless you're scalping M1 or trading news.

    2. Humans can't watch the screen 24/7, so they use pending orders; EAs can, so no need for pending orders, have it wait until the market reaches the trigger price and just open an order.

 
//+------------------------------------------------------------------+
//| Delete all pending orders at the specified time                  |
//+------------------------------------------------------------------+
void DeletePendingOrders()
  {
   for (int i = OrdersTotal() - 1; i >= 0; i--)
     {
      if (OrderSelect(i,SELECT_BY_POS))
        {
         int orderType = (int)OrderGetInteger(ORDER_TYPE);
         if (orderType == ORDER_TYPE_BUY_STOP || orderType == ORDER_TYPE_SELL_STOP)
           {
            ulong ticket = OrderGetTicket();
            if (!trade.OrderDelete(ticket))
              {
               Print("Error deleting pending order: ", GetLastError());
              }
            else
              {
               Print("Pending order deleted: ", ticket);
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
Sergey Golubev #:

please edit your post -

--------------------------

When you post code please use the CODE button (Alt-S)!