19/05/2026
Two EAs on the same account were closing each other's positions. No error. No warning in the MetaTrader logs.
The cause is `OrderSelect()`. Every loop in MQL4 that iterates open positions — trailing stops, breakeven checks, basket-close sweeps — sees every order on the account. Not just the EA's own. Every order placed by every strategy running in the same terminal.
Without an `OrderMagicNumber()` ownership check in the modification loop, one EA's housekeeping routine becomes an account-wide override.
We traced three patterns across client accounts this year. A trailing-stop EA updating stop-losses on positions placed by a mean-reversion EA it never knew existed. A breakeven EA closing scalper trades at the wrong moment because it counted total positions, not its own. A basket-close EA flattening end-of-day orders on EURUSD from every strategy on the account — by symbol, not by magic number.
In each case, the EAs were technically correct in isolation. The failure was structural: no ownership filter in the loops that act across positions.
The fix is one condition — `OrderMagicNumber() == MAGIC` — added to every loop that modifies, closes, or counts orders. It must appear in three places: before any `OrderModify()` or `OrderClose()` call, inside position-count functions used for risk budgeting, and in any basket operation that iterates the full order pool.
If your portfolio account has been generating unexplained behavior — positions closed at wrong prices, SLs moved overnight — verify this before re-evaluating any strategy.