Close_Delete_Everthing_ASAP_Now_Profit_Hour
Download scriptThis automated script is designed as a "safety net" or an emergency management tool for your trading account. Its primary purpose is to identify specific conditions under which all active trades and pending orders across all currency pairs (symbols) should be closed immediately.
How the Logic Works
The script constantly monitors your account and triggers a total liquidation of positions based on three specific "exit switches." If any one of these three conditions is met, the script will systematically close every open trade and delete every pending order until the account is completely clear.
1. The Time-Based Trigger (CloseHour) The script allows you to set a specific hour of the day. If the current market time matches the hour you have defined, the script activates. This is useful for traders who want to ensure no positions are left open overnight or during periods of high volatility outside of their trading session.
2. The Profit Target Trigger (CloseProfit) This acts as a "take-profit" ceiling for your entire account. It looks at the difference between your current Equity (the value of your account including open gains/losses) and your Balance (your cash total). If your floating profit exceeds the specific amount you have set in the settings, the script will trigger and close everything to lock in those gains.
3. The Manual Override (CloseNow) This serves as an immediate manual switch. By changing a single setting value, you can force the script into "active mode" regardless of the time or your current profit levels. This allows for an instant, automated cleanup of all market activity.
Operational Behavior
- Continuous Scanning: The script runs in a loop, constantly checking your account status against these three rules.
- Total Clearance: Unlike standard tools that might only close one trade at a time, this logic is designed to be exhaustive. It will continue to cycle through your open positions until every single trade and pending order is removed from the platform.
- Automatic Reset: If none of the three conditions are met (i.e., it isn't the designated hour, you aren't at the profit target, and the manual switch is off), the script remains idle and does not interfere with your active trades.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+-------------------------------------------------------------------------+
//| Close_Delete_Everything_ASAP_Now_Profit_Hour.mq4 |
//| Copyright © 2006, transport_david |
//|http://finance.groups.yahoo.com/group/MetaTrader_Experts_and_Indicators/ |
//+-------------------------------------------------------------------------+
//---------------------------------------------------------------------------
// When This Runs It Closes And Deletes Every Trade On All Symbols ,
// Will Not Stop Untill There Are No Current Trades Or Orders .
//---------------------------------------------------------------------------
#property copyright "Copyright © 2006, transport_david"
#property link "http://finance.groups.yahoo.com/group/MetaTrader_Experts_and_Indicators/"
extern int CloseNow = 0; // Any value other than 0 == CloseMAll True
//----------------------------------------------------------------------------------------------
// Re-Set CloseProfit value AFTER you have attached this expert to the Chart(s) .
// Use the Properties Window
extern int CloseProfit = 500000000; // ( (Equity - Balance) > CloseProfit ) == CloseMAll True
// Use the Properties Window
// Re-Set CloseProfit value AFTER you have attached this expert to the Chart(s) .
//----------------------------------------------------------------------------------------------
extern int CloseHour = 24; // > 23 == disabled
int i;
bool CloseMAll;
int start()
{
///////////////////////////////////
// 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;
}
}
}
////////////////////////////////
// data checks
////////////////////////////////
if ((Hour()!=CloseHour) && (CloseNow==0) && ((AccountEquity()-AccountBalance()) < CloseProfit)) { CloseMAll = false; }
if ((Hour()==CloseHour) || (CloseNow!=0) || ((AccountEquity()-AccountBalance()) > CloseProfit)) { CloseMAll = true; }
return(0);
}
Comments