Skip to content
Terminal Ledger Desk
Directory

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.

By Marcus Thorne, CQFReview not recorded · Updated
MT5 Netting vs Hedging Position Ledgers: Orders, Deals, CloseBy & Margin Math — Terminal Ledger Desk 2026 quantitative & supervisory data card
Terminal Ledger Desk (MetaTrader 5, cTrader & Liquidity Bridge Server Topology & Execution Logs): Order/Deal/Position separation, 0-spread CloseBy annihilation, and rollover hedge-lock traps.Source: Terminal Ledger Desk Institutional Research DeskLicense: CC-BY-4.0

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:

  1. Order (HistoryOrderSelect / OrderSelect): An instruction to buy or sell (NewOrderSingle). Once filled, it moves immediately to Order History.
  2. Deal (HistoryDealSelect): An immutable atomic trade execution (ExecutionReport 150=F) stamped DEAL_ENTRY_IN, DEAL_ENTRY_OUT, DEAL_ENTRY_INOUT (reversal!), or DEAL_ENTRY_OUT_BY (CloseBy).
  3. Position (PositionSelect / PositionSelectByTicket): The live open market exposure sporting a persistent POSITION_IDENTIFIER linking every entry, partial scale-in, and closing deal across its entire lifecycle!
MT5 Order -> Deal -> Position relational ledger contrasting Netting single-position DEAL_ENTRY_INOUT flips against Hedging multi-ticket CloseBy annihilation
MT5 Order -> Deal -> Position relational ledger contrasting Netting single-position DEALENTRYINOUT flips against Hedging multi-ticket CloseBy annihilationVerified Exhibit

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 Netting Mode (Mandatory for Exchange Equities/Futures & US NFA Rule 2-43b FIFO): A symbol can have at most ONE net position! Selling 3.0 Lots generates a single DEAL_ENTRY_INOUT deal that closes the 2.0 Long (realizing +$1,000) and flips the single symbol position directly to Short 1.0 Lot @ 1.0850! Margin required: 1.0 Lot.
  • In Hedging Mode (Global Non-US OTC FX/CFD Default): Selling 3.0 Lots without specifying request.position opens a brand-new independent Short 3.0 Lot ticket alongside your Long 2.0 Lot ticket (Gross = 5.0 Lots, Net = Short 1.0 Lot)! Margin required depends on broker SYMBOL_MARGIN_HEDGED:
  • 0% Hedged Margin: Matched 2.0 x 2.0 hedged pairs cost $0 extra margin (paying only on 1.0 uncovered lot—dangerous at 17:00 EST rollover spread widening!).
  • 50% (1-Leg Covered) or 100% (Both Legs): Charges margin on the larger leg (3.0 Lots) or sum (5.0 Lots).
Quantitative Distribution · NETTING (MARGINMODERETAIL_NETTING)
NETTING (MARGINMODERETAIL_NETTING)
01Max Open Positions / SymbolStrictly 1 (Wei…02Stop-Loss / Take-Profit Sco…1 Symbol-Wide S…03US NFA / Exchange Legality100% Compliant …04Overnight Rollover Swap CostPaid/earned on …
Accounting DimensionNETTING (MARGIN_MODE_RETAIL_NETTING)HEDGING (MARGIN_MODE_RETAIL_HEDGING)Engineering & Risk Implication
Max Open Positions / SymbolStrictly 1 (Weighted-average VWAP)Unlimited (Independent ticket IDs)Multi-EA portfolios prefer Hedging (Magic#)
Opposite-Side Market OrderReduces, closes, or reverses (INOUT)Opens new opposite ticket unless position set!Forgetting request.position leaves lock open!
Stop-Loss / Take-Profit Scope1 Symbol-Wide SL / TPIndependent SL / TP per ticketNetting scales require partial Limit orders
US NFA / Exchange Legality100% Compliant (FIFO / Exchange CLOB)Prohibited in US Retail FX (NFA 2-43b)Institutional APIs (FIX) default to Netting
Overnight Rollover Swap CostPaid/earned on 1.0 Net Lot onlyPaid 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.

Formula or model from the articleNot independently verified
Margin_Total_Hedging = Margin_Uncovered(|V_buy - V_sell|) + min(V_buy, V_sell) * Margin_Hedged_Per_Pair
  • 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.

Used margin in USD on Long 4 Lots + Short 3 Lots EUR/USD (1:30 ESMA/FCA leverage) across Netting, Hedging 0% Leg, Hedging 50% Largest-Leg, and Hedging 100% Gross
Used margin in USD on Long 4 Lots + Short 3 Lots EUR/USD (1:30 ESMA/FCA leverage) across Netting, Hedging 0% Leg, Hedging 50% Largest-Leg, and Hedging 100% GrossVerified Exhibit

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

Open Attribution License (CC BY 4.0)

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-recalculation
Explore Mt5 Ctrader Bridge Dealer Architecture Hub (20) →

Terminal Ledger Desk Data, Benchmarks & Contributor Records

MT5 Netting vs Hedging Ledgers, CloseBy & Margin Math | Terminal Ledger Desk