Clear The Board Bee-otch
Download scriptThis script is designed as an automated risk management tool for the MetaTrader platform. Its primary purpose is to act as a "hard stop" for your trading activities, ensuring that no positions remain open overnight or past a specific point in time.
How it Works
The logic of the script revolves around two primary triggers: the current time of day and a manual override switch. Here is a breakdown of how the system processes these instructions:
1. Time-Based Monitoring The script constantly monitors the server's clock. You can define a specific hour (for example, 11:00 PM) during which you want your trading floor to be completely cleared. When the clock hits this designated hour, the script recognizes that the "trading day" is over.
2. Manual Override There is a secondary setting that allows you to force the script into action regardless of the time. If this specific toggle is activated, the script will treat every moment as a "closing moment," immediately identifying any active trades for removal.
3. The Clearing Process Once either the specific hour is reached or the manual override is turned on, the script initiates a systematic cleanup:
- It scans your entire account to identify all currently open trades and pending orders.
- It moves through this list one by one, systematically closing every active position at the current market price.
- After closing a trade, it removes any lingering "pending" orders (limit or stop orders) that have not yet been triggered.
Summary of Benefit
Essentially, this tool serves as an automated "safety net." It prevents the risk of holding positions during volatile periods (such as over-the-weekend gaps or late-night market shifts) by automatically cleaning your workspace and ensuring you start the next trading session with a neutral balance and no active exposure.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+-------------------------------------------------------------------------+
//| Clear The Board Bee-otch.mq4 |
//| Copyright © 2006, transport_david |
//|http://finance.groups.yahoo.com/group/MetaTrader_Experts_and_Indicators/ |
//+-------------------------------------------------------------------------+
#property copyright "Copyright © 2006, transport_david"
#property link "http://finance.groups.yahoo.com/group/MetaTrader_Experts_and_Indicators/"
extern int CloseHour = 23;
extern int CloseNow = 1;
int i;
bool CloseMAll;
int start()
{
////////////////////////////////
// initial data checks
////////////////////////////////
if ((Hour()!=CloseHour) && (CloseNow==0)) { CloseMAll = false; }
if ((Hour()==CloseHour) || (CloseNow==1)) { CloseMAll = true; }
///////////////////////////////////
// close/delete all trades/orders
///////////////////////////////////
if (CloseMAll == true)
{
for(i = OrdersTotal()-1; i >=0 ; i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if (OrdersTotal() != 0)
{
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,White);
OrderDelete( OrderTicket() );
CloseMAll = true;
}
}
}
return(0);
}
Comments