Close_all_profitable_positions Profit
Download scriptThis automated tool is designed to streamline your trading by monitoring your open positions and automatically closing them once they reach a specific financial milestone. Instead of requiring you to manually watch the markets and click "close" as soon as your profit goal is met, this script handles that process for you in real-time.
How it Works
The script operates on a continuous loop, scanning through every active trade currently held in your trading account. It evaluates each position individually to determine its current status and performance.
Key Functionalities
- Automated Profit Monitoring: The logic is centered around a specific monetary goal. You can define a target amount (in dollars), and the script will constantly check if the profit of any open trade has reached or exceeded that value.
- Intelligent Trade Identification: The system distinguishes between different types of market actions—specifically "Buy" positions and "Sell" positions. It recognizes how each type behaves differently in the market to ensure it executes the correct closing price for each individual trade.
- Automatic Execution: Once a trade hits your predefined profit target, the script immediately sends an instruction to the broker to close that position. This ensures that your gains are locked in instantly, minimizing the risk of a sudden market reversal turning a winning trade into a loss.
- Stability and Reliability: To ensure the process is smooth, the script includes a brief "waiting" period if it encounters any issues closing a specific order. This prevents the system from overwhelming your connection and allows it to retry the action efficiently.
Summary for the User
In simple terms, this tool acts as an automated "Take Profit" manager. It sits in the background of your platform, watching your trades 24/7. The moment any position earns you the amount of money you’ve designated, the script closes it automatically, allowing you to secure your profits without having to be glued to your screen.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| close-all-orders.mq4 |
//| Copyright © 2005, Matias Romeo. |
//| Custom Metatrader Systems. |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Matias Romeo."
#property link "mailto:matiasDOTromeoATgmail.com"
extern int ProfitTarget = 10; // Profit target in dollars
int start()
{
int total = OrdersTotal();
for(int i=total-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
int type = OrderType();
bool result = false;
switch(type)
{
//Close opened long positions
case OP_BUY : if ( OrderProfit() >= ProfitTarget) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
break;
//Close opened short positions
case OP_SELL : if ( OrderProfit() >= ProfitTarget) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
}
if(result == false)
{
//Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
Sleep(300);
}
}
return(0);
}
Comments