EA-59371 · Utility

AutoCloseOnProfitLoss

This EA monitors the total floating profit/loss of all open positions and automatically closes all positions when either a target profit or maximum loss threshold is reached. It serves as an account-level profit/loss manager that acts as a global take-profit and stop-loss for the entire portfolio.

Open the interactive view (equity curve, symbol switch)

Key facts

CategoryUtility
RiskLow
Rating★★☆☆☆
TypeUtility tool
TimeframesM1, M5, M15, M30, H1, H4, D1
Indicators—
AuthorYour Name, 2025

Backtest results (H1, about 1 year)

Not backtested yet — this EA could not be converted automatically.

Strategy analysis

This EA is essentially an account-level profit/loss management utility that does not involve any entry strategy or position-opening logic. Its core concept is to monitor the cumulative floating profit/loss of all positions, and when total profit reaches the target or total loss hits the maximum tolerance, it closes all positions. Entry conditions are entirely determined by the user or other EAs; this EA does not open positions. Exit conditions are: close all positions when total profit >= TargetProfit, or close all positions when total loss <= MaxLoss. Regarding position sizing, the EA does not perform any lot calculation or adjustment—it only handles closing. For money management, it implements account-level take-profit and stop-loss control via the TargetProfit and MaxLoss parameters, but lacks risk isolation for individual positions. The strategy logic is simple and direct, making it suitable as a supplementary tool alongside other trading EAs.

Strengths

  • Simple and clear logic, easy to understand and use, suitable for novice traders
  • Provides account-level global take-profit and stop-loss, effectively preventing excessive losses or greedy holding
  • Supports independent toggle for profit-close and loss-close functions, offering high flexibility
  • Uses the CTrade class for closing operations, following MQL5 standard programming conventions
  • Thorough input parameter validation prevents abnormal behavior from incorrect user input

Weaknesses

  • Calculates total profit/loss and prints logs on every tick, causing massive redundant log output that impacts performance and log readability
  • No retry mechanism for closing positions; closing may fail without retries during network latency or extreme market volatility
  • Does not account for commissions and swap costs; relying solely on floating P&L may cause actual closing results to differ from expectations
  • CloseAllPositions only loops once; if some positions fail to close, it does not retry closing remaining positions
  • Lacks filtering by specific symbol or magic number, which will close all positions including those from other EAs

Possible improvements

  • Add filtering by symbol and magic number to avoid accidentally closing positions from other EAs
  • Switch to new bar or timer-based triggering instead of every tick to reduce redundant logging and computation overhead
  • Add a retry mechanism with delayed retries for failed closing attempts to improve closing success rate
  • Include commissions and swap costs in the profit/loss calculation to make total P&L closer to actual account changes
  • Add option to close only profitable or only losing positions for more flexible money management strategies

Risk assessment

Overall risk: Low

  • Printing logs on every tick can seriously impact performance and generate massive redundant logs, potentially causing delays during fast market conditions
  • No retry mechanism for closing means some positions may not be closed in time during extreme market conditions
  • No magic number filtering will close positions from all EAs, potentially conflicting with other strategies

Evaluation scores

Code quality3.0
Strategy logic2.0
Risk management3.0
Robustness2.0
Innovation1.0
Documentation2.0
Overall2.2

Parameters

ParameterDefaultDescription
TargetProfit100.0Target profit amount (account currency), closes all positions when reached
MaxLoss-50.0Maximum loss limit in currency
EnableProfitClosetrueEnable auto close on target profit reached
EnableLossClosetrueEnable auto close on maximum loss reached
ShowAlertstrueWhether to show popup alerts on position close

Similar Utility EAs

Backtests are historical simulations and do not guarantee future results. Not financial advice.

Get the weekly Arena report

One email a week: ranking changes, new signals and new research. No spam; unsubscribe any time.