CloseOrDeleteAll
Download scriptThis script is designed as a comprehensive "emergency reset" tool for your trading platform. Its primary purpose is to perform an immediate and complete cleanup of all active trading activities across your entire account simultaneously.
Instead of closing trades one by one or focusing on specific assets, this tool scans every open position and pending order you have. Here is the logic it follows:
Comprehensive Scanning The script looks at your entire account history in real-time. It does not distinguish between different types of currencies, stocks, or commodities (Symbols), nor does it filter by specific identification numbers (Magic Numbers). If there is an active order on your screen, the script identifies it.
Active Trade Liquidation For positions that are currently open and active in the market—specifically "Buy" and "Sell" positions—the script automatically executes a closing command. It handles the technical details of calculating the current market price to ensure the trade is exited immediately at the best available rate.
Pending Order Removal The script also identifies "pending" orders. These are orders you have placed but have not yet been triggered (such as "Stop" or "Limit" orders waiting for the price to hit a certain level). The script finds these and deletes them from your watch list entirely so they cannot be executed in the future.
Execution Style The tool is designed for "immediate execution." As soon as it is activated, it runs a continuous loop that keeps checking for remaining orders until every single one is closed or removed. It provides visual feedback on the chart (indicated by a purple color marker) to signal that it is performing these actions.
In short, this is a "panic button" utility used to wipe the slate clean, removing all market exposure and pending instructions in one swift motion.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| CloseOrDeleteAll.mq4|
//| Paul Hampton-Smith|
//+------------------------------------------------------------------+
// Cleans up all orders regardless of Symbol() or Magic
void init()
{
// immediate execution
while(OrdersTotal()>0)
{
OrderSelect(0, SELECT_BY_POS, MODE_TRADES);
switch (OrderType())
{
case OP_BUY: OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(),MODE_BID), 5, Purple); break;
case OP_SELL: OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(),MODE_ASK), 5, Purple); break;
case OP_BUYSTOP:
case OP_SELLSTOP:
case OP_BUYLIMIT:
case OP_SELLLIMIT: OrderDelete(OrderTicket());
}
}
}
void start()
{
// nothing more to do
}
Comments