AutoCloseOnProfitLoss Expert - Automatically close all positions based on profit and loss - Expert for MetaTrader 5
AutoCloseOnProfitLoss Expert Advisor (EA) is a powerful automated tool for MetaTrader 5 designed to close all open positions when a predefined profit or loss target is reached. This EA is ideal for traders who want to manage risk and ensure profits without human intervention. Whether you are a scalper looking for quick profits or a long-term trader protecting capital, this EA provides a reliable, hands-free solution.
The EA monitors the total profit or loss of all open positions using the PositionGetDouble(POSITION_PROFIT) function in MetaTrader 5. It compares this value to user-defined target profit and maximum loss thresholds. If any of the conditions are met (and the corresponding feature is enabled), the EA will close all positions with market orders and notify the user via alerts (if enabled) and in the terminal log.
Suppose you set Target Profit = 100.0 , Max Loss = -50.0 , Enable Profit Closing = true , and Enable Loss Closing = true . If your open positions reach total profit of $120, the EA will close all positions and display a warning: "All positions closed! Reason: Target profit: 120.00 reached". If the total loss reaches -$60, the EA will close all positions and issue a warning: "All positions closed! Reason: Maximum loss reached: -60.00".
If you have suggestions or encounter problems, please leave a comment on the MQL5 Codebase page or contact me through the MQL5 Community. Your feedback is very valuable to improve this tool!
Author: Du Van Nguyen
touch: MQL5 link
Update date: May 14, 2025
Platform: MetaTrader 5
Category: Expert Advisor
Attachment download
📎 autocloseonprofitloss.mq5 (5.86 KB)
Source: MQL5 #59371
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •