Exp-Close-----SELLStop-------

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

This script is designed as a management tool for MetaTrader users who need to quickly clean up their trading environment by identifying and removing specific types of pending orders. Instead of manually searching through a list of trades, this automation handles the "housekeeping" of your account based on the rules you set before running it.

Core Functionality

The primary purpose of this script is to scan your active trading portfolio and automatically delete Sell Stop orders. A Sell Stop is a pending order placed at a price below the current market value, intended to trigger a sale if the price drops to a certain level.

How it Works

When you execute the script, it follows a specific logical flow to determine which actions to take:

  • Global Cleanup vs. Specific Symbol Cleanup: The script gives you a choice in its settings. It can be set to "Global Mode," where it looks at every single open order across all different currency pairs or assets in your account. Alternatively, it can be restricted to "Local Mode," where it only interacts with the specific chart you currently have open.
  • Targeted Identification: The logic specifically filters for orders of the "Sell Stop" type. It ignores active trades (Buy/Sell positions already running) and other types of pending orders (like Buy Limits), focusing exclusively on the Sell Stops you wish to clear.
  • Sequential Processing: The script starts from the bottom of your order list and works its way up. This is a standard safety procedure in trading software to ensure that as it removes one order, the numbering of the remaining orders doesn't shift and cause the script to skip any entries.
  • Error Reporting: If the script encounters an issue—such as an order being closed by another process at the exact same millisecond or a connection glitch—it is designed to capture that specific error and display it in the terminal logs, allowing you to see exactly why a certain action might have failed.

Visual Feedback

When the script is initialized, it creates a small visual "stamp" on your chart. This serves as a branding indicator and a confirmation that the tool has been loaded into your workspace correctly.

Summary for the User

Think of this script as a "selective delete" button. It is highly useful for traders who want to instantly wipe out all pending Sell Stop orders across their entire account or just on one specific pair, ensuring that no unwanted sell triggers remain active in the market.

Orders Execution
Checks for the total of open orders
13 Views
0 Downloads
0 Favorites
Exp-Close-----SELLStop-------
#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;extern bool AllSymbols=true;
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+

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_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_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