A_DeleteAllPending

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

This script is designed to provide a quick and efficient way to clear out pending trade orders from your trading platform. It automates the process of identifying and removing "waiting" orders that have not yet been executed, allowing you to clean up your workspace without having to delete each order manually.

How it works:

1. Identification Phase When you run the script, it first performs a comprehensive scan of all your active and pending trade requests. It distinguishes between "live" trades (active Buy or Sell positions) and "pending" orders (orders waiting to be triggered at a specific price). The script specifically ignores live positions to ensure they remain untouched.

2. Inventory Count During the initial scan, the tool calculates exactly how many pending orders are currently active on your account. It then outputs this total count into the system log so you can see exactly how many items are slated for removal.

3. Selective Removal Once the script knows which orders are pending, it begins a systematic deletion process. It looks specifically for orders that match the currency pair (symbol) of your current chart. To ensure accuracy and avoid errors, it processes these one by one, confirming each deletion as it goes.

4. Verification and Reporting As the script works through the list, it monitors the success of each deletion. If an order is successfully removed, it moves to the next; if the system encounters an issue preventing a specific order from being closed, it captures that specific error and reports it back to you.

Key Takeaways for the User:

  • Safety: The script is programmed to leave your active trades alone; it only targets orders that are still "pending."
  • Automation: It eliminates the tedious task of clicking through dozens of individual orders to delete them one by one.
  • Accuracy: By verifying symbols and order types, the tool ensures that only the intended types of orders are removed from your account.
Orders Execution
Checks for the total of open orders
4 Views
0 Downloads
0 Favorites
A_DeleteAllPending
//+------------------------------------------------------------------+
//|                                             DeleteAllPending.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
int totalPendingOrders = 0;   // variable to count total pending Orders

//+------------------------------------------------------------------+
//| script "Delete All pending orders"                              |
//+------------------------------------------------------------------+
int start()
  {
   bool   isDeleted;       //To check order deleted is successful or not
   int    Order_Type, total;
//----
   total=OrdersTotal();    //getting total orders including open and pending
//----
//+------------------------------------------------------------------+
//| counting total pending orders                                    |
//+------------------------------------------------------------------+
   
   
   for(int a=0; a<total; a++)
     {
      if(OrderSelect(a,SELECT_BY_POS,MODE_TRADES))
        {
         Order_Type=OrderType();
         //---- pending orders only are considered
         if(Order_Type!=OP_BUY && Order_Type!=OP_SELL)
           {
            totalPendingOrders++;
            }
         }
   }
   
   //Displaying number or total pending orders
   Print("Total Pending Orders "+totalPendingOrders);
   
   
   //Selecting pending orders and deleting first order in the loop till last order
   for(int i=0; i<totalPendingOrders; i++)
     {
     for(int b=0; b<totalPendingOrders; b++)
      {
      if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
        {
         Order_Type=OrderType();
         //---- pending orders only are considered
         if(Order_Type!=OP_BUY && Order_Type!=OP_SELL&& Symbol()==OrderSymbol())
           {
            //---- print selected order
            OrderPrint();
            //---- delete first pending order
            isDeleted=OrderDelete(OrderTicket());
            if(isDeleted!=TRUE) Print("LastError = ", GetLastError());
            break;
           }
        }
      else { Print( "Error when order select ", GetLastError()); break; }
     }
//----
   }
   return(0);
  }
//+------------------------------------------------------------------+*/

Comments