PZ_DeleteAllPendingOrders

Download script
PZ_DeleteAllPendingOrders

This script is a specialized utility designed to streamline your trading workspace by clearing out outstanding "limit" or "stop" orders that have not yet been triggered.

How it Works

The tool functions as a safety and organization mechanism for your trading platform. Instead of requiring you to manually go through every open request to cancel them one by one, this script automates the entire process in a single click. Here is the logical flow of how it handles your account:

1. User Confirmation Before taking any action, the script triggers a pop-up notification. It asks for your explicit permission to proceed. This ensures that orders are not deleted accidentally; the process only moves forward if you manually confirm that you want to clear your pending requests.

2. Intelligent Scanning Once confirmed, the script begins a comprehensive scan of your current trading activity. It looks at every open order in your account and applies three specific filters:

  • Symbol Matching: It identifies orders specifically tied to the chart you currently have open. This prevents it from affecting trades on different currency pairs or assets.
  • Order Type Identification: It specifically looks for "Pending" orders—those waiting for the price to hit a certain level (such as Buy Limits, Sell Limits, Buy Stops, or Sell Stops).
  • Exclusion of Active Trades: Importantly, it ignores any trades that are already active (in profit or loss). It only targets orders that have not yet been executed.

3. Automated Removal For every order that meets these criteria, the script automatically executes a deletion command. If for some reason an order cannot be deleted (due to server restrictions or connection issues), the script logs the specific error in the platform's background diary so you can review it later.

4. Completion Once the scan is finished, the script provides a simple copyright notice on the screen to indicate that the process is complete, leaving you with a clean trading chart focused only on your active positions.

Orders Execution
Checks for the total of open orders
Miscellaneous
It opens Message Boxes to the user
3 Views
0 Downloads
0 Favorites
PZ_DeleteAllPendingOrders
//+------------------------------------------------------------------+
//| PZ_DeleteAllPendingOrders.mq4
//| --
//| This script deletes all non-executed pending orders.
//+------------------------------------------------------------------+
#property copyright "Copyright © http://www.pointzero-trading.com"
#property link      "http://www.pointzero-trading.com"

//---- Dependencies
#import "stdlib.ex4"
   string ErrorDescription(int e);
#import
#include <stdlib.mqh>
#include <WinUser32.mqh>

//-- Don't change me
#define  ShortName            "PZ Delete All Pending Orders"
#define  Shift                1

//-- Internal
double   LastOrderLots = EMPTY_VALUE;
double   LastOrderPrice;
double   DecimalPip;

//+------------------------------------------------------------------+
//| Custom Script start function                           
//+------------------------------------------------------------------+
int start()
{
   // Confirm
   if(MessageBox(ShortName +" - Do you really want to delete all pending orders?",
                 "Script",MB_YESNO|MB_ICONQUESTION)!=IDYES) return(1);
  
   // Order type
   int Type;
   
   // Iterate orders
	for(int i = OrdersTotal()-1; i >= 0; i--)
	{
		OrderSelect(i, SELECT_BY_POS, MODE_TRADES); Type = OrderType();
		if(OrderSymbol() == Symbol())
		{ 
	      if(Type == OP_BUYSTOP || Type == OP_SELLSTOP || Type == OP_BUYLIMIT || Type == OP_SELLLIMIT)  
	      {
            if(!OrderDelete(OrderTicket()))
               Print(ShortName +" (OrderDelete Error) "+ ErrorDescription(GetLastError()));
         }
      }
   }

   // Hi there!
   Comment("Copyright © http://www.pointzero-trading.com");
   
   // Bye
   return(0);
}


Comments