delete_pending

Download script
Author: Copyright � 2004, MetaQuotes Software Corp.
delete_pending

This automated script is designed to simplify the management of your trading account by quickly cleaning up inactive orders. Its primary purpose is to identify and remove "pending" orders—these are trades that have been set up in advance but have not yet been triggered or executed by the market.

How it Works

The script follows a straightforward, step-by-step process to organize your active trade list:

  1. Account Scan: Once activated, the script scans your entire trading account to see how many active orders are currently open.
  2. Identification: It looks through each order one by one to determine its status. It specifically distinguishes between "active trades" (trades currently running in the market) and "pending orders" (trades waiting for a specific price to be hit).
  3. Targeting: The logic is designed to ignore your current active positions. It only focuses on those pending instructions that have not yet moved into a live trade.
  4. Execution: As soon as the script identifies the very first pending order in its list, it automatically deletes it from the platform.
  5. Safety Stop: To prevent the script from clearing out your entire list of pending orders at once, it is programmed to stop immediately after successfully deleting the first one it finds.

Key Benefits for the User

Instead of manually hunting through a long list of limit or stop orders to delete them individually, this tool provides a "one-click" solution. It ensures that you can clear out outdated entries without accidentally closing your currently active profit or loss positions. If the script encounters any issues while trying to remove an order, it will provide a notification in the system log so you can stay informed about the status of your account.

Orders Execution
Checks for the total of open orders
15 Views
0 Downloads
0 Favorites
delete_pending
//+------------------------------------------------------------------+
//|                                               delete_pending.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"
#property show_confirm

//+------------------------------------------------------------------+
//| script "delete first pending order"                              |
//+------------------------------------------------------------------+
int start()
  {
   bool   result;
   int    cmd,total;
//----
   total=OrdersTotal();
//----
   for(int i=0; i<total; i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         cmd=OrderType();
         //---- pending orders only are considered
         if(cmd!=OP_BUY && cmd!=OP_SELL)
           {
            //---- print selected order
            OrderPrint();
            //---- delete first pending order
            result=OrderDelete(OrderTicket());
            if(result!=TRUE) Print("LastError = ", GetLastError());
            break;
           }
        }
      else { Print( "Error when order select ", GetLastError()); break; }
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments