CloseMall_Hour_Input
Download scriptThis automated script is designed to act as a safety net for your trading activities by automatically managing your open positions based on the time of day. Its primary purpose is to ensure that no trades remain active once a specific hour has been reached, allowing for a "hands-off" approach to risk management at the end of a trading session.
How it Works
The logic follows a straightforward three-step process:
1. Time Monitoring The script constantly monitors the current server time. You can set a specific target hour (for example, 11:00 PM) in the settings. The system is programmed to look specifically at this numerical value every time the market updates.
2. Trigger Identification The software performs a continuous check: "Is it currently the hour I have specified?"
- If the current hour does not match your setting, the script remains idle and does not interfere with your trades.
- If the current hour does match your setting, the script activates its closing sequence.
3. Automated Order Liquidation Once the specific hour is triggered, the script scans your active trading account. It looks for any open positions associated specifically with the currency pair or asset you are currently viewing. For every matching trade it finds, it performs two actions:
- It closes the position at the current market price.
- It removes the pending order from the system.
By automating this process, the script removes the need for manual intervention during late-night hours or specific session closes, ensuring that your capital is not exposed to market movements after your preferred trading window has ended.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| CloseMall_Hour_Input.mq4 |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
extern int CloseHour = 23;
int i;
bool CloseMAll;
int start()
{
////////////////////////////////
// initial data checks
////////////////////////////////
if (Hour()!=CloseHour) { CloseMAll = false; }
if (Hour()==CloseHour) { CloseMAll = true; }
///////////////////////////////////
// Determine trades/orders and close/delete all trades/orders
///////////////////////////////////
if (CloseMAll == true)
{
for(i = OrdersTotal()-1; i >=0 ; i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if (OrderSymbol() == Symbol())
{
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,White);
OrderDelete( OrderTicket() );
CloseMAll = true;
}
}
}
return(0);
}
Comments