A utility Expert Advisor that automatically closes all open positions (and optionally pending orders) when a defined profit or loss threshold is reached — across the current symbol or all symbols simultaneously.
Designed for traders who want a simple, reliable account-level safety net without manual intervention. Key features:
- unified `CloseAll()` logic with configurable symbol scope and pending order handling
- dynamic profit/loss color coding on the info panel (green / red)
- panel displays active TP and SL thresholds at a glance
- aligned two-column panel layout with visual separators
- proper cleanup of all panel objects on `OnDeinit()`
The profit row changes color dynamically: **green** when the combined P&L is positive, **red** when negative.
---
## How It Works
On every tick the EA:
1. Calculates the combined floating P&L (profit + swap) of all matching positions.
2. If P&L exceeds `profitToClose` → closes all matching positions (and optionally pending orders).
3. If P&L drops below `-lossToClose` → same action.
4. If a close attempt fails, it retries on the next tick until successful.
---
## Installation
1. Copy `_Close_at_PRofit.mq5` to `MQL5/Experts/`.
2. Compile in MetaEditor (F7) — should produce zero errors/warnings.
3. Attach to any chart. The EA does not open positions on its own.
4. Configure `profitToClose` / `lossToClose` to match your risk management rules.
> **Tip:** Set `Magic = -1` to manage all positions regardless of which EA opened them, or enter a specific magic number to manage only one strategy's trades.