Exp-Close-----BUYStop-------

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

This script is designed as an automated utility for MetaTrader users to manage and clean up pending trade orders within their trading environment. Its primary function is to identify and remove specific types of "Buy Stop" orders automatically, helping traders maintain a clean workspace and ensure that only active, relevant trades remain in their portfolio.

Core Functionality

The tool operates by scanning your current trading accounts to find any open Buy Stop orders. A Buy Stop is a pending order placed at a price above the current market price, intended to trigger a purchase if the market moves upward to that specific level.

Key Operating Modes

The script provides two distinct ways to handle these orders based on user preference:

  • Global Management (All Symbols): When this mode is active, the script acts as a comprehensive cleaner. It will scan every single currency pair, commodity, or asset in your trading account and remove all Buy Stop orders regardless of which instrument they belong to.
  • Specific Asset Management: If this mode is disabled, the script becomes more selective. It will only target and remove Buy Stop orders for the specific chart or symbol you currently have open on your screen, leaving your other pending orders on different symbols untouched.

Execution Process

When executed, the logic follows a systematic three-step process:

  1. Identification: The script systematically reviews your list of active trades from the bottom up to ensure it captures every single entry.
  2. Filtering: It checks each order to see if it matches two criteria: is it a "Buy Stop" type, and does it belong to the targeted symbol(s)?
  3. Removal: Once an order meets the criteria, the script attempts to delete it immediately. If for any reason an order cannot be removed (such as a connection issue or trade restriction), the script is designed to log an error message so the user can see why the action failed.

Visual Identification

To indicate that the tool has been initialized correctly, the script places a small visual label on your trading chart. This serves as a confirmation that the utility is active and ready to perform its tasks within your workspace.

Orders Execution
Checks for the total of open orders
11 Views
0 Downloads
0 Favorites
Exp-Close-----BUYStop-------
#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)  && !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)  && !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