close_all_DragDrop

Download script
Author: what?
close_all_DragDrop

This script is designed as an automated utility for the MetaTrader platform to manage and clear active trading positions and pending orders instantly. Its primary function is to perform a comprehensive cleanup of your current trading environment on a specific financial instrument.

Core Functionality

The script operates by scanning all currently open transactions in your account. It systematically identifies every active trade associated with the specific market symbol you are currently viewing and takes the following actions:

  • Active Trade Liquidation: For any open "Buy" positions, the script automatically executes a closing command at the current market price. Conversely, for any open "Sell" positions, it performs an immediate exit at the prevailing market rate.
  • Pending Order Removal: The script also identifies "limit" and "stop" orders—these are trades that have not been triggered yet but are waiting at specific price points. It removes these pending instructions from the system entirely.

Operational Behavior

The logic follows a "sweep" approach. Instead of targeting a single trade, it iterates through your entire order list. It ignores trades from other symbols, ensuring that its actions are confined only to the asset you are currently monitoring. By refreshing the market data in real-time as it runs, it ensures that the closing prices used are the most accurate available at that exact microsecond.

Use Case

This tool is essentially a "panic button" or a "clean slate" utility. It is intended for traders who need to instantly flatten their exposure, cancel all outstanding plans, and reset their trading screen to a neutral state without having to manually close each position one by one.

Orders Execution
Checks for the total of open ordersIt Closes Orders by itself
12 Views
0 Downloads
0 Favorites
close_all_DragDrop
#property copyright "what?"
#property link      "who cares!"

//+------------------------------------------------------------------+
//| couldn't recall a fancy comment here                             |
//+------------------------------------------------------------------+
int start()
  {
//----
   //int digits   = MarketInfo(Symbol(),MODE_DIGITS);
   //double value = NormalizeDouble(WindowPriceOnDropped(),digits);
   for(int i=OrdersTotal()-1;i>=0;i--)
   {
      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         continue;
      if(OrderSymbol()!=Symbol())
         continue;
      
      RefreshRates();
      
      if(OrderType()==OP_BUY)           
         OrderClose(OrderTicket(),OrderLots(),Bid, 3,White);
      if(OrderType()==OP_SELL)    
         OrderClose(OrderTicket(),OrderLots(),Ask, 3,White);
      if((OrderType()==OP_BUYSTOP) || (OrderType()==OP_BUYLIMIT))           
         OrderDelete(OrderTicket());
      if((OrderType()==OP_SELLSTOP) || (OrderType()==OP_SELLLIMIT))
         OrderDelete(OrderTicket());
   }   
   return(0);
  }
//+------------------------------------------------------------------+

Comments