Discussing the article: "Building a FIFO-Compliant Position Management Layer for NFA-Regulated MQL5 Accounts"

Check out the new article: Building a FIFO-Compliant Position Management Layer for NFA-Regulated MQL5 Accounts.

This article shows how to make EA close operations comply with broker-enforced FIFO (ACCOUNT FIFO CLOSE) on hedging accounts, so naive exits stop failing. It introduces CFifoPositionQueue to order an EA's own tickets by time and CFifoComplianceGuard to execute closes in two modes: strict reject or auto-cascade, with optional per-direction scope. The guard re-verifies eligibility before each step, normalizes volumes, and inspects real server retcodes. You get reusable code, tests, and clear limits.

MQL5 exposes "AccountInfoInteger(ACCOUNT_FIFO_CLOSE)," a documented account property that reports directly whether an account requires closing positions in FIFO order—the oldest ticket on a symbol first, regardless of which ticket a strategy actually wants to reduce. A number of regulated brokers, most commonly those under NFA oversight in the United States, enforce this on hedging-mode accounts, and when they do, a close request against anything but the oldest ticket is rejected outright with "TRADE_RETCODE_FIFO_CLOSE" (10045).

Two classes divide this problem along a now-familiar line: one answers a pure ordering question with no live access at all, the other owns everything that actually touches the trade server.

Consider a simple pyramiding strategy: it adds to a position in the direction of a trend, producing several separate tickets on the same symbol opened at different times. A common exit rule for this kind of strategy is to trim the most recent add first—it has the least accumulated profit and the tightest stop, so cutting it loose first is a reasonable risk decision on its own terms.

Author: Tola Moses Hector