Mt5 Ctrader Bridge Dealer Architecture
MT5 Netting vs Hedging Position Ledgers: Orders, Deals, CloseBy & Margin Math
When MetaQuotes launched MT5 with institutional Netting-only accounting, retail FX EA developers revolted until Build 1325 added Hedging—creating two distinct server ledger modes with radically different margin and CloseBy behavior.

Nothing trips up developers porting strategies from MT4—or from institutional futures OMS platforms—onto MetaTrader 5 faster than its strict three-entity database schema (Orders != Deals != Positions) combined with dual ACCOUNT_MARGIN_MODE_RETAIL_NETTING vs ACCOUNT_MARGIN_MODE_RETAIL_HEDGING ledgers! Understanding why institutional exchanges mandate Netting, why retail grid EAs demand Hedging, and how ORDER_TYPE_CLOSE_BY saves an entire bid-ask spread when collapsing hedged legs prevents costly margin-call surprises.
The Three-Entity MT5 Ledger: Order -> Deal -> Position#
In legacy MT4, everything was crammed into one flat Order ticket (OrderSelect). Inside the MetaTrader 5 Server Cluster, accounting mirrors institutional FIX 4.4 / Clearing standards by strictly separating:
Order(HistoryOrderSelect/OrderSelect): An instruction to buy or sell (NewOrderSingle). Once filled, it moves immediately to Order History.Deal(HistoryDealSelect): An immutable atomic trade execution (ExecutionReport 150=F) stampedDEAL_ENTRY_IN,DEAL_ENTRY_OUT,DEAL_ENTRY_INOUT(reversal!), orDEAL_ENTRY_OUT_BY(CloseBy).Position(PositionSelect/PositionSelectByTicket): The live open market exposure sporting a persistentPOSITION_IDENTIFIERlinking every entry, partial scale-in, and closing deal across its entire lifecycle!
Netting (1 Position/Symbol) vs Hedging (N Positions/Symbol + Hedged Margin)#
Compare what happens when you hold Long 2.0 Lots EUR/USD @ 1.0800 and submit Sell 3.0 Lots EUR/USD @ 1.0850 across the two MT5 Terminal modes:
- In
NettingMode (Mandatory for Exchange Equities/Futures & US NFA Rule 2-43b FIFO): A symbol can have at most ONE net position! Selling3.0 Lotsgenerates a singleDEAL_ENTRY_INOUTdeal that closes the2.0Long (realizing +$1,000) and flips the single symbol position directly toShort 1.0 Lot @ 1.0850! Margin required:1.0 Lot. - In
HedgingMode (Global Non-US OTC FX/CFD Default): Selling3.0 Lotswithout specifyingrequest.positionopens a brand-new independentShort 3.0 Lotticket alongside yourLong 2.0 Lotticket (Gross = 5.0 Lots,Net = Short 1.0 Lot)! Margin required depends on brokerSYMBOL_MARGIN_HEDGED: 0% Hedged Margin: Matched2.0 x 2.0hedged pairs cost$0extra margin (paying only on1.0uncovered lot—dangerous at17:00 ESTrollover spread widening!).50%(1-Leg Covered) or100%(Both Legs): Charges margin on the larger leg (3.0 Lots) or sum (5.0 Lots).
| Accounting Dimension | NETTING (MARGIN_MODE_RETAIL_NETTING) | HEDGING (MARGIN_MODE_RETAIL_HEDGING) | Engineering & Risk Implication |
|---|---|---|---|
| Max Open Positions / Symbol | Strictly 1 (Weighted-average VWAP) | Unlimited (Independent ticket IDs) | Multi-EA portfolios prefer Hedging (Magic#) |
| Opposite-Side Market Order | Reduces, closes, or reverses (INOUT) | Opens new opposite ticket unless position set! | Forgetting request.position leaves lock open! |
| Stop-Loss / Take-Profit Scope | 1 Symbol-Wide SL / TP | Independent SL / TP per ticket | Netting scales require partial Limit orders |
| US NFA / Exchange Legality | 100% Compliant (FIFO / Exchange CLOB) | Prohibited in US Retail FX (NFA 2-43b) | Institutional APIs (FIX) default to Netting |
| Overnight Rollover Swap Cost | Paid/earned on 1.0 Net Lot only | Paid on both Long AND Short legs (Net Loss!) | Never hold hedged locks across 17:00 EST! |
MT5 Netting vs Hedging Accounting & Regulatory Compliance Matrix#
Side-by-side ledger behavior, MQL5 API traps, and regulatory legality across US, EU/UK, and global venues.
- EquityLockedHedge = Balance + FixedPnLLocked - (Askt - Bidt) * ContractSize * min(Vbuy, Vsell)
- Worked Rollover Trap on a "100% Locked" 0%-Margin Hedge (Balance = $2,000, Buy 10 Lots + Sell 10 Lots EUR/USD):
- Daytime (0.2 pip spread) : Floating Spread Loss = -0.2 * $10 * 10 = -$200 -> Equity = $1,800 (Safe)
- 17:00 EST (19.0 pip widen) : Floating Spread Loss = -19.0 * $10 * 10 = -$1,900 -> Equity drops to $100 -> STOP-OUT!
Saving 100% of the Exit Spread With ORDER_TYPE_CLOSE_BY (DEAL_ENTRY_OUT_BY)#
Suppose a trader on a Hedging account locked exposure during news by holding Position #101: Buy 5.0 Lots XAU/USD and Position #102: Sell 5.0 Lots XAU/USD. How do novices unwind that lock? They click Close #101 (crossing Bid) AND Close #102 (crossing Ask)—paying the XAU/USD spread TWICE (wasting ~$175) and risking price drift between the two clicks!
Instead, execute TRADE_ACTION_CLOSE_BY (request.position = 101, request.position_by = 102)! Because the two positions already offset each other 100% on the server ledger, the MT5 Trade Server annihilates both tickets atomically against each other (DEAL_ENTRY_OUT_BY) with ZERO LP spread paid, ZERO slippage, and ZERO extra commission on most ECNs! Review upstream bridge mapping in our MT5, cTrader & Liquidity Bridge Architecture Guide and stop-out liquidation cascades.
Writing Dual-Mode Portable MQL5 Expert Advisors#
Never call PositionSelect(_Symbol) inside a multi-strategy EA on a Hedging account! PositionSelect(string symbol) returns only the first/lowest ticket on that symbol, blinding your second EA! Always iterate for (int i = PositionsTotal - 1; i >= 0; i--) using PositionGetTicket(i) filtered by both _Symbol AND POSITION_MAGIC!
Audit hedged rollover margin cushions inside the Terminal Margin VaR & ES Calculator and explore MQL5 async patterns in the MT5, cTrader & Bridge Topic Hub.
Frequently asked questions
Why did the US National Futures Association (NFA Rule 2-43b) ban Hedging on retail FX accounts?
In 2009, the NFA banned retail FX hedging and mandated FIFO closing after proving that holding simultaneous Long and Short positions in the exact same currency pair provides zero economic payoff difference vs closing, while charging retail traders double spreads and negative net overnight swaps.
Why do algorithmic traders outside the US still prefer MT5 Hedging accounts when running multiple EAs?
Hedging simplifies software isolation when running 5 independent Expert Advisors on EUR/USD (e.g., a 5-minute scalper alongside a 4-hour trend follower): each EA manages its own isolated ticket SL/TP via Magic Number without modifying a shared Netting symbol SL.
How does ORDER_TYPE_CLOSE_BY work when the Buy and Sell hedged positions have different lot sizes?
If Position #1 is Buy 5.0 Lots and Position #2 is Sell 2.0 Lots, CloseBy atomically closes 2.0 Lots of both positions against each other at zero extra spread, leaving Position #1 open with 3.0 remaining Buy Lots at its original entry price!
Can I switch an existing live MT5 account from Hedging to Netting mid-month?
No. Because Netting and Hedging use incompatible server-side position aggregation engines inside MT5 account groups, changing accounting mode requires opening a new sub-account inside the target Netting or Hedging broker group.
Publication record
- Published
- 13 November 2026
- Updated
- 14 November 2026
- Author
- Marcus Thorne, CQF
- Review
- Review not recorded
- Automated fact check
- Passed in the stored pipeline record
- Source URLs
- 3 recorded
AI assistance recorded: anthropic/claude-opus-4.6. This field does not establish human review or source verification.
Academic & Institutional Attribution
Cite This Research & Embed Live Data Card
Standard academic & institutional research paper citation format.
Marcus Thorne, CQF. (2026, November 14). MT5 Netting vs Hedging Position Ledgers: Orders, Deals, CloseBy & Margin Math. Terminal Ledger Desk. https://terminalledgerdesk.com/reports/mt5-netting-vs-hedging-account-position-ledger-margin-recalculationRelated Mt5 Ctrader Bridge Dealer Architecture & Institutional Briefings
Explore Mt5 Ctrader Bridge Dealer Architecture Hub (20) →Mt5 Ctrader Bridge Dealer Architecture
MetaTrader 5, cTrader & Liquidity Bridge Server Topology & Execution Logs GuideMt5 Ctrader Bridge Dealer Architecture
OTC FX Last-Look Hold Windows: FX Global Code Principle 17 & Firm Liquidity TCAMt5 Ctrader Bridge Dealer Architecture
Margin Stop-Out Liquidation Engines: Tick Evaluation, Smart Partial Close & NBPMt5 Ctrader Bridge Dealer Architecture
PAMM, MAM & Copy-Trading Engines: Master-to-Child Allocation Latency & SlippageMt5 Ctrader Bridge Dealer Architecture
FX Swap Rollover Engines: Triple-Wednesday T+2 Settlement & Tom-Next Batch MathMt5 Ctrader Bridge Dealer Architecture
WebAssembly & WebGL Browser Trading Terminals: Holding 16.6ms 60-FPS Frame BudgetsMt5 Ctrader Bridge Dealer Architecture
Prime-of-Prime Net Open Position (NOP) Gates: Credit Throttling in FX BridgesMt5 Ctrader Bridge Dealer Architecture
MQL5 High-Speed EA Architecture: OnTick Drop Behavior & OrderSendAsync PipesMifid Rts6 Pretrade Kill Switch Controls
CME Globex Velocity Logic & Dynamic Circuit Breakers: Sub-Second Futures Volatility GuardsMifid Rts6 Pretrade Kill Switch Controls
CFTC Regulation 1.73: FCM Automated Pre-Execution Clearing Credit Screens & Give-Up LimitsMifid Rts6 Pretrade Kill Switch Controls
Options Market-Maker Mass Quote Risk (MMR): Rolling Delta, Vega & Percentage-Swept Purge TriggersMifid Rts6 Pretrade Kill Switch Controls
Runaway Loop & Quote-Stuffing Detection: Stateful Duplicate-Order & Reject-Storm Gates
Terminal Ledger Desk Data, Benchmarks & Contributor Records
CC BY 4.0 Open Data
Open Institutional Datasets (CSV / JSON) →
Download desk-compiled quantitative series & schemas.
2026 Reference Matrix
2026 Institutional Benchmarks & Thresholds →
Statutory capital, clearing, margin & rate conventions.
Editorial Records
Authors & Review Records →
View named contributors where those records are available.
Complete Index
Master Research & Dossier Archive →
Browse all published briefings by topic pillar & date.
