Close_All_Pending

Download script
Author: (c) 2007 Investatech Inc., www.investatech.com
Close_All_Pending

This automated script is designed to manage and clear out active pending orders within a trading account on the MetaTrader platform. Its primary purpose is to "clean up" the workspace by removing any outstanding instructions that have not yet been executed as live trades.

How it Works

The logic follows a systematic process to ensure all non-active orders are removed:

  • Scan and Identify: The script starts by looking at every open position and pending order currently associated with your account. It systematically checks each individual order to identify its specific type (such as "Buy Limits" or other forms of pending requests).
  • Filtering Actions: While the script is capable of identifying different types of trades, it is specifically programmed to act on pending orders. When it detects an order that is set to trigger in the future (rather than a trade that is already currently running), it sends a command to delete that request immediately.
  • Repetition for Accuracy: To ensure that no orders are missed during the scanning process, the script performs its check multiple times in a quick sequence. This "looping" mechanism helps account for the way the trading platform updates its list as orders are being removed.
  • Verification: Once the script finishes its cycles, it checks your account one last time.
    • If no pending orders remain, it displays a notification confirming that the job is finished successfully.
    • If there are still active pending orders remaining, it will trigger an alert informing you that some orders were not cleared and suggesting that you run the script again.

In short, this tool acts as a "clearance" button for your trading dashboard, removing all "waiting" orders to leave your account organized.

Orders Execution
Checks for the total of open orders
Miscellaneous
It issuies visual alerts to the screen
16 Views
0 Downloads
0 Favorites
Close_All_Pending
//+------------------------------------------------------------------+
//|                                               Close_All_Open.mq4 |
//|                  (c) 2007  Investatech Inc., www.investatech.com |
//|                                       http://www.investatech.com |
//+------------------------------------------------------------------+
#property copyright "(c) 2007  Investatech Inc., www.investatech.com"
#property link      "http://www.investatech.com"
#property show_inputs
#include <stdlib.mqh>

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   for (int i=0;i<5;i++)
      {
         int total_trades=OrdersTotal();
   
         if (total_trades==0) 
           {
            Alert("Job Done! Visit http://www.pipboxer.com");
            return(0);
           }
   
         for(int j=0;j<total_trades;j++)
            {
              if(OrderSelect(j,SELECT_BY_POS,MODE_TRADES)) 
               {
                  int order_type=OrderType();
                  double order_openprice=OrderOpenPrice();
                  int order_ticket=OrderTicket();
                  double order_volume=OrderLots();
                  string order_symbol=OrderSymbol();
                  
                  //close pending orders
                  if (order_type>=OP_BUYLIMIT) OrderDelete(order_ticket,CLR_NONE);
                  
                  //close sell orders
                  //if (order_type==OP_SELL) OrderClose(order_ticket,order_volume,MarketInfo(order_symbol,MODE_ASK),3,CLR_NONE);

                  
                  //close buy orders
                  //if (order_type==OP_BUY) OrderClose(order_ticket,order_volume,MarketInfo(order_symbol,MODE_BID),3,CLR_NONE);
               }
            }
      }
   total_trades=OrdersTotal();
   
   if (total_trades>0)
      Alert("Something went wrong! Repeat the script.");
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments