CloseAllPendingAdvanced
Download scriptThis script is designed as a management tool for MetaTrader traders who need to quickly clean up their active trading dashboard by removing specific types of pending orders. Instead of manually deleting each order one by one, this tool automates the process based on precise criteria that you can customize.
How the Logic Works
When you run this script, it performs a comprehensive scan of all your currently open pending orders in your trading account. It evaluates every order against a set of "filters" to determine whether or not it should be removed.
The logic follows these primary steps:
1. Filtering by Specific Identifiers The script allows you to target only specific groups of trades so that you don't accidentally delete everything. You can choose to:
- Target a Specific Currency Pair: You can set the script to only interact with one specific symbol (e.g., EURUSD).
- Magic Number Filtering: If you use automated trading robots (EAs), you can use "Magic Numbers" to tell the script to only delete orders placed by a specific robot, or conversely, to ignore a specific one.
2. Selective Order Deletion The core functionality of the tool is its ability to distinguish between different types of pending orders. It looks for four specific categories:
- Buy Limit Orders: Orders set to buy at a lower price.
- Stop Buy Orders: Orders set to buy once the price rises to a certain level.
- Sell Limit Orders: Orders set to sell at a higher price.
- Stop Sell Orders: Orders set to sell once the price drops to a certain level.
3. Customizable Actions Through the settings, you have full control over which of these categories are affected. You can toggle each type on or off individually. For example, if you want to keep your "Buy Limit" orders but want to clear all "Stop Sell" orders instantly, you can configure the script to perform only that specific action.
Summary of Operation
In short, the script acts as a "smart filter." It looks at your entire list of pending trades, checks them against your personal preferences (Which currency? Which robot? Which order type?), and then automatically removes the ones that match your criteria. This provides a fast, reliable way to manage market exposure and declutter your trading platform in seconds.
//+------------------------------------------------------------------+
//| CloseAllPendingAdvance.mq4 |
//| ThinkTrustTrade |
//| www.think-trust-trade.com |
//+------------------------------------------------------------------+
#property copyright "ThinkTrustTrade"
#property link "www.think-trust-trade.com"
#property show_inputs
extern string Visit="www.think-trust-trade.com";
extern string Like="www.facebook.com/ThinkTrustTrade";
extern bool limit_buy=true;
extern bool stop_buy=true;
extern bool limit_sell=true;
extern bool stop_sell=true;
extern int only_magic=0;
extern int skip_magic=0;
extern bool only_below_symbol=false;
extern string symbol="EURUSD";
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
//----
bool deleted;
if (OrdersTotal()==0) return(0);
for (int i=OrdersTotal()-1; i>=0; i--)
{//pozicio kivalasztasa
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true)//ha kivalasztas ok
{
//Print ("order ticket: ", OrderTicket(), "order magic: ", OrderMagicNumber(), " Order Symbol: ", OrderSymbol());
if (only_magic>0 && OrderMagicNumber()!=only_magic) continue;
if (skip_magic>0 && OrderMagicNumber()==skip_magic) continue;
if (only_below_symbol==true && OrderSymbol()!=symbol)
{Print("order symbol different"); continue;}
if (OrderType()==2 && limit_buy==true)
{//ha long
//Print ("Error: ", GetLastError());
deleted=OrderDelete(OrderTicket());
//Print ("Error: ", GetLastError(), " price: ", MarketInfo(OrderSymbol(),MODE_BID));
if (deleted==false) Print ("Error: ", GetLastError());
if (deleted==true) Print ("Order ", OrderTicket() ," Deleted. Thank you for using our script! Visit www.think-trust-trade.com for more free tools.");
}
if (OrderType()==4 && stop_buy==true)
{//ha short
//Print ("Error: ", GetLastError());
deleted=OrderDelete(OrderTicket());
//Print ("Error: ", GetLastError(), " price: ", MarketInfo(OrderSymbol(),MODE_ASK));
if (deleted==false) Print ("Error: ", GetLastError());
if (deleted==true) Print ("Order ", OrderTicket() ," Deleted. Thank you for using our script! Visit www.think-trust-trade.com for more free tools.");
}
if (OrderType()==3 && limit_sell==true)
{//ha long
//Print ("Error: ", GetLastError());
deleted=OrderDelete(OrderTicket());
//Print ("Error: ", GetLastError(), " price: ", MarketInfo(OrderSymbol(),MODE_BID));
if (deleted==false) Print ("Error: ", GetLastError());
if (deleted==true) Print ("Order ", OrderTicket() ," Deleted. Thank you for using our script! Visit www.think-trust-trade.com for more free tools.");
}
if (OrderType()==5 && stop_sell==true)
{//ha short
//Print ("Error: ", GetLastError());
deleted=OrderDelete(OrderTicket());
//Print ("Error: ", GetLastError(), " price: ", MarketInfo(OrderSymbol(),MODE_ASK));
if (deleted==false) Print ("Error: ", GetLastError());
if (deleted==true) Print ("Order ", OrderTicket() ," Deleted. Thank you for using our script! Visit www.think-trust-trade.com for more free tools.");
}
}
}//pozicio kivalszatas vege
//----
return(0);
}
//+------------------------------------------------------------------+
Comments