SmallHelp@Close
Download scriptThis script is designed to act as an automated "profit-taker" for your trading account. Its primary function is to monitor active trades and automatically close them the moment they reach a specific profit threshold.
Core Functionality
The logic revolves around a predefined minimum profit target. The script constantly scans your open positions to identify any trade that has reached or exceeded this value. Once a qualifying trade is found, the script executes an immediate sell/buy order to exit the position and lock in the gains.
Key Operational Behaviors:
- Instant Execution: The script is designed to run continuously. As soon as your profit hits the target, the system triggers the closing command without requiring manual intervention.
- Trade Differentiation: The logic distinguishes between different types of trades (Buy and Sell). It identifies whether a position is a "Buy" or a "Sell" to ensure it closes the trade at the correct market price.
- Recursive Closing: The script is structured to check for multiple trades sequentially. If one trade is closed, it immediately looks for the next eligible trade that meets the profit criteria, ensuring that all profitable positions are cleared in rapid succession.
- Initialization Safety: Upon being loaded onto a chart, the script performs an initial sweep of your open trades. This means it will check for and close any currently active trades that are already in profit before it begins its routine monitoring.
Summary for the User
Think of this tool as a "safety net" for your profits. It automates the most critical moment of trading—exiting at the right time—by removing the emotional element of waiting. If a trade meets your minimum profit requirement, the script handles the exit for you instantly, allowing you to maintain a disciplined trading strategy.
//=====================================================================================================================================================
double MinProfit=0.0001;
//=====================================================================================================================================================
int init()
{
TradeCloseBuy();
TradeCloseSell();
return(0);
}
int deinit()
{
return(0);
}
int start()
{
TradeCloseBuy();
TradeCloseSell();
return(0);
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------
double TradeClose()
{
if(OrderSelect(OrderTicket(),SELECT_BY_TICKET)==true)
{
if(OrderProfit()>=MinProfit)
{
if(OrderType()==OP_BUY)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Green);
TradeClose();
}
if(OrderType()==OP_SELL)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Green);
TradeClose();
}
}
}
return(0);
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------
double TradeCloseBuy()
{
if(OrderSelect(OrderTicket(),SELECT_BY_TICKET)==true)
{
if(OrderProfit()>=MinProfit)
{
if(OrderType()==OP_BUY)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Green);
TradeClose();
}
}
}
return(0);
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------
double TradeCloseSell()
{
if(OrderSelect(OrderTicket(),SELECT_BY_TICKET)==true)
{
if(OrderProfit()>=MinProfit)
{
if(OrderType()==OP_SELL)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Green);
TradeClose();
}
}
}
return(0);
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------
Comments