Exp-Close-----ALLSTOP------

Download script
Author: expforex
Exp-Close-----ALLSTOP------

This script is an automated utility designed for the MetaTrader trading platform to manage and clear pending orders quickly. Its primary function is to identify and remove specific types of "waiting" trades from your account based on your preference for scope.

Core Functionality

The logic follows a straightforward "search and delete" process:

1. Order Filtering The script specifically targets Pending Orders—specifically "Buy Stop" and "Sell Stop" orders. It does not interfere with active trades (like正在 running Buy or Sell markets) or other types of pending orders. It focuses only on these specific triggers that are waiting to be activated.

2. Scope Selection You have the option to choose how broad the script's reach should be:

  • Global Cleanup: If enabled, the script scans your entire trading account and removes the specified pending orders across every currency pair or asset you trade.
  • Specific Asset Cleanup: If disabled, the script restricts its actions only to the specific chart or symbol you currently have open.

3. Automated Execution Once activated, the script performs a comprehensive sweep of your active order list. It moves through your trades one by one; if it finds an order that matches the "Buy Stop" or "Sell Stop" criteria, it immediately sends a command to the server to cancel it.

4. Error Reporting and Feedback To ensure transparency, the script includes a built-in reporting mechanism. If it encounters any issue while trying to delete an order (such as a connection problem or a trade being locked), it captures that specific error message and prints it to the terminal log. This allows you to see exactly why a particular order might have remained open.

5. Visual Branding Upon execution, the script places a small text label on your trading chart. This serves as a signature, identifying the source of the tool and providing a reference link for the developer.

Orders Execution
Checks for the total of open orders
9 Views
0 Downloads
0 Favorites
Exp-Close-----ALLSTOP------
#property show_inputs
#property copyright "expforex"
#property link      "http://expforex.at.ua"
//+------------------------------------------------------------------+
//| EX4 imports                                                      |
//+------------------------------------------------------------------+
#include <stdlib.mqh>
//+------------------------------------------------------------------+
//| global variables to program:                                     |
//+------------------------------------------------------------------+
double Price[2];
int    giSlippage;
bool   CloseOpenOrders = true;
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
extern bool AllSymbols=true;
void init()
{

Stamp();
start();
}
void start() {
  int iOrders=OrdersTotal()-1, i;
  
  
 if (AllSymbols==true){ 
 
  if(CloseOpenOrders) {
    for(i=iOrders; i>=0; i--) {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && (OrderType()==OP_BUYSTOP||OrderType()==OP_SELLSTOP)  && !OrderDelete(OrderTicket())) Print(OrderError());
    }
  }}
  
 
  if (AllSymbols==false){ 
 
  if(CloseOpenOrders) {
    for(i=iOrders; i>=0; i--) {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if( OrderSymbol()!=Symbol())continue; if ( OrderSymbol()==Symbol() && (OrderType()==OP_BUYSTOP||OrderType()==OP_SELLSTOP)  && !OrderDelete(OrderTicket())) Print(OrderError());}
    }
  }}
 
}
//+------------------------------------------------------------------+
//| Function..: OrderError                                           |
//+------------------------------------------------------------------+
string OrderError() {
  int iError=GetLastError();
  return(StringConcatenate("Order:",OrderTicket()," GetLastError()=",iError," ",ErrorDescription(iError)));
}
//+------------------------------------------------------------------+
//| Function..: GetMarketInfo                                        |
//+------------------------------------------------------------------+
bool GetMarketInfo() {
  RefreshRates();
  Price[0]=MarketInfo(OrderSymbol(),MODE_ASK);
  Price[1]=MarketInfo(OrderSymbol(),MODE_BID);
  double dPoint=MarketInfo(OrderSymbol(),MODE_POINT);
  if(dPoint==0) return(false);
  giSlippage=(Price[0]-Price[1])/dPoint;
  return(Price[0]>0.0 && Price[1]>0.0);
}
//+------------------------------------------------------------------+

void Stamp(){

   ObjectCreate("Original", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("Original", " ---http://Expforex.at.ua---", 10, "Arial Bold", Red);
   ObjectSet("Original", OBJPROP_CORNER, 2);
   ObjectSet("Original", OBJPROP_XDISTANCE, 200);
   ObjectSet("Original", OBJPROP_YDISTANCE, 10);


}

Comments