Introduction
The AutoCloseOnProfitLoss Professional Advisor (EA) is a strong automation software for MetaTrader 5, designed to shut all open positions when predefined revenue or loss targets are reached. This EA is ideal for merchants who need to handle threat and safe income with out handbook intervention. Whether or not you are a scalper focusing on fast features or a long-term dealer defending capital, this EA presents a dependable, hands-free answer.
Options
- Automated Place Closing: Robotically closes all open positions when the overall revenue or loss meets the required threshold.
- Customizable Targets: Set revenue and loss targets in your account foreign money (e.g., USD, EUR).
- Versatile Choices: Independently allow or disable closing based mostly on revenue or loss.
- Consumer Notifications: Shows alerts and logs within the terminal when positions are closed.
- Environment friendly and Light-weight: Runs constantly with minimal CPU utilization, excellent for ongoing commerce administration.
How It Works
The EA screens the overall revenue or lack of all open positions utilizing the PositionGetDouble(POSITION_PROFIT) perform in MetaTrader 5. It compares this worth in opposition to the user-defined TargetProfit and MaxLoss thresholds. If both situation is met (and the corresponding function is enabled), the EA closes all positions utilizing market orders and notifies the consumer via alerts (if enabled) and terminal logs.
Set up
- Obtain the AutoCloseOnProfitLoss.ex5 file from the hyperlink on the backside of this web page.
- Open MetaTrader 5 and go to File > Open Knowledge Folder.
- Navigate to MQL5 > Consultants and replica the .mq5 file into this folder.
- Restart MetaTrader 5 or refresh the Navigator panel.
- Find the EA within the Navigator below Professional Advisors, then drag it onto a chart to activate.
Enter Parameters
- TargetProfit (default: 100.0): The revenue goal in your account foreign money to shut all positions.
- MaxLoss (default: -50.0): The utmost loss in your account foreign money (should be a damaging worth) to shut all positions.
- EnableProfitClose (default: true): Allow or disable closing positions when the goal revenue is reached.
- EnableLossClose (default: true): Allow or disable closing positions when the utmost loss is reached.
- ShowAlerts (default: true): Allow or disable alerts in MetaTrader 5 when positions are closed.
Utilization
- Drag the AutoCloseOnProfitLoss EA onto any chart in MetaTrader 5.
- Within the dialog field that seems, configure the enter parameters:
- Set your required TargetProfit and MaxLoss values.
- Allow or disable revenue/loss closing as wanted.
- Select whether or not to show alerts.
- Click on OK to begin the EA.
- The EA will constantly monitor all open positions and shut them if the required circumstances are met.
- Examine the Consultants or Journal tab in MetaTrader 5 for logs and outcomes.
Instance
Suppose you set TargetProfit = 100.0, MaxLoss = -50.0, EnableProfitClose = true, and EnableLossClose = true. In case your open positions attain a complete revenue of $120, the EA will shut all positions and show an alert: “All positions closed! Motive: Goal revenue reached: 120.00”. If the overall loss reaches -$60, the EA will shut all positions with an alert: “All positions closed! Motive: Max loss reached: -60.00”.

Notes
- The EA requires open positions to take motion; in any other case, it would log the present revenue/loss and proceed monitoring.
- Positions are closed utilizing market orders, so slippage could happen relying on market circumstances.
- Take a look at the EA on a demo account first to make sure it fits your buying and selling technique.
- Not like a script, this EA runs constantly till manually stopped or faraway from the chart.
Suggestions
If in case you have solutions or encounter points, please depart a touch upon the MQL5 CodeBase web page or contact me via the MQL5 group. Your suggestions is efficacious for enhancing this software!
—————————————————— —————————————————— —————————————-
Uncover my premium merchandise and elevate your buying and selling at the moment:
✔️ XAU OneShot EA MT5©: https://www.mql5.com/en/market/product/126057
✔️ Breakout Grasp EA MT5©: https://www.mql5.com/en/market/product/137818