New free code from MQL5: indicators, EAs, and scripts for traders.
Close By Filter closes only the positions you choose, instead of everything at once. Pick the side, the symbol, the magic number and whether the position is in profit or in loss. The script lists what matches, shows the floating result and asks before it changes anything.

The confirmation box: what will be closed and the floating result
Capture price channel breakouts with the Price Channel Expert Advisor. Precise entries and exits. Explore now.
What it does
- Filters by side (buys, sells or both), symbol (this chart or all symbols), magic number (any, manual trades only, or one magic number) and result (any, only in profit, only in loss).
- Can also delete the matching pending orders (limit, stop and stop-limit orders on the chosen side). Pending orders are deleted first, so none can fill while the positions are being closed.
- Shows a confirmation box with the number of positions and orders and the current floating result (profit + swap).
- Checks the filters again just before each close, because prices move while the box is open.
- Finds each position by its position ID, so a ticket change during the run does not cause a wrong report.
- Never sends a close twice for the same position: on a netting account a second close would open a new position the other way.
- Retries on requotes, price changes, time-outs and connection errors, and stops at once on errors that a retry cannot fix (for example, market closed).
- Sets the order filling mode from the symbol's own settings.
- Reports what was closed, skipped, already gone or failed in the Experts tab. Failures, and pending orders that filled before they could be deleted, also raise an alert.

The result after the run
Inputs

The script's inputs
- Which side: buys and sells, buys only, or sells only.
- Which symbols: this chart's symbol only (default) or all symbols.
- Magic number: -1 = any, 0 = no magic number (usually manual trades), any other number = only that magic number.
- Profit filter: any result, only positions in profit, or only positions in loss (profit + swap).
- Also delete matching pending orders: false by default.
- Ask before closing: true by default. Set it to false only if you are sure of your filters.
- Maximum slippage (points).
- Attempts per position or order.
Notes: tick "Allow Algo Trading" on the script's Common tab, and switch Algo Trading on in the terminal. Test it on a demo account first.
Thanks for reading. Discover premium MetaTrader solutions at RobotFX.
80098