# MT5 Netting vs Hedging Ledgers, CloseBy & Margin Math

> Contrast MT5 Netting (US FIFO/Exchange) vs Hedging position accounting, Order/Deal/Position separation, CloseBy (ORDER_TYPE_CLOSE_BY), and margin math.

Canonical: https://terminalledgerdesk.com/reports/mt5-netting-vs-hedging-account-position-ledger-margin-recalculation
Last updated: 2026-11-14T19:41:49.691Z

**Publication:** Terminal Ledger Desk
**Category:** Mt5 Ctrader Bridge Dealer Architecture
**Published:** 2026-11-13T21:30:25.915Z
**Author:** Marcus Thorne, CQF (Certificate in Quantitative Finance (CQF), Low-Latency FIX & Matching Engine Architect)
**Reviewer:** Not recorded

## Answer-first summary

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.

## Key takeaways

- MT5 strictly separates Orders (instructions), Deals (immutable executions), and Positions (net or ticket inventory linked via persistent POSITION_IDENTIFIER).
- On Hedging accounts, submitting an opposite-direction order without specifying request.position opens a second locked position instead of closing the first!
- Always unwind opposing hedged positions using TRADE_ACTION_CLOSE_BY (DEAL_ENTRY_OUT_BY) to collapse both legs atomically while saving 100% of the exit spread.
- Beware the "risk-free hedge" myth: widening spreads at 17:00 EST rollover plus negative combined Long+Short swaps routinely trigger Stop-Outs on over-leveraged hedged locks!

## Related financial entities

- **Financial Information eXchange (FIX) Protocol** (FIX-4.4) — product: Electronic communications protocol initiated in 1992 for international real-time exchange of securities transaction and market data information.
- **MetaTrader 5 Multi-Server Cluster Architecture** (MT5-CORE) — product: Enterprise 64-bit distributed client-server architecture developed by MetaQuotes Software supporting multi-asset netting and hedging execution models.
- **Unified Multi-Asset Clearing Engine Standard** (UNIFIED-MARGIN) — product: Universal clearing engine that aggregates distinct financial asset classes into a single real-time valuation, netting collateral and exposures simultaneously.

## Analysis

Nothing trips up developers porting strategies from `MT4`—or from institutional futures OMS platforms—onto [MetaTrader 5](/software/mt5) 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](/engines/metatrader-5-server-cluster), accounting mirrors institutional [FIX 4.4 / Clearing](/engines/unified-margin-clearing-engine) 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](/api/figure?type=flow&title=MT5%20Three-Entity%20Ledger%3A%20Netting%20Flip%20vs%20Hedging%20%2B%20CloseBy&subtitle=Separating%20immutable%20Deals%20from%20net%2Fhedged%20Positions%20and%200-spread%20ORDER_TYPE_CLOSE_BY&steps=1.%20Order%20%28Intent%29%3A%3AMqlTradeRequest%20validated%20%26%20archived%7C2.%20Atomic%20Deal%3A%3ADEAL_ENTRY_IN%20%2F%20OUT%20%2F%20INOUT%20%2F%20OUT_BY%7C3.%20Netting%20Mode%3A%3ABuy%202%20%2B%20Sell%203%20-%3E%201%20Short%201.0%20Position%7C4.%20Hedging%20Mode%3A%3A2%20Tickets%20-%3E%20Collapse%200-spread%20CloseBy!&metrics=CLOSEBY%20SPREAD%3A%3A0.0%20Pips%3A%3ASaves%201%20full%20bid-ask%20spread!%7CNFA%20RULE%202-43B%3A%3ANet%20%2F%20FIFO%3A%3ABans%20OTC%20FX%20hedging%20in%20USA%7CNETTINGvwap%3A%3AWeighted%20Avg%3A%3AAuto-recomputes%20avg%20entry%20px%7CSAFE%20SELECTOR%3A%3AGetTicket%28i%29%3A%3ANever%20PositionSelect%28sym%29!)

## 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](/platforms/mt5-terminal-2) modes:
- **In `Netting` Mode (Mandatory for Exchange Equities/Futures & US [NFA](/standards/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`).

| 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](/standards/nfa) / Exchange Legality** | **100% Compliant** (`FIFO` / Exchange CLOB) | **Prohibited in US Retail FX (`NFA 2-43b`)** | Institutional APIs ([FIX](/software/fix-api)) 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.

```formula
Margin_Total_Hedging = Margin_Uncovered(|V_buy - V_sell|) + min(V_buy, V_sell) * Margin_Hedged_Per_Pair
Equity_Locked_Hedge = Balance + Fixed_PnL_Locked - (Ask_t - Bid_t) * ContractSize * min(V_buy, V_sell)

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](/reports/mt5-ctrader-liquidity-bridge-server-topology-execution-logs-guide) and [stop-out liquidation cascades](/reports/stop-out-liquidation-cascades-margin-level-tick-evaluation-engines).

![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](/api/figure?type=bars&title=Margin%20Required%20on%20Long%204.0%20%2B%20Short%203.0%20EUR%2FUSD%20%28%40%201%3A30%29&subtitle=Comparing%20initial%20margin%20locked%20%28%24108%2C500%2Flot%20notional%20-%3E%20%243%2C617%2Flot%20%40%203.33%25%20margin%29&steps=Netting%20Mode%20%28Net%20%2B1.0%20Lot%29%3A%3A%243%2C617%20margin%20%20%20Only%201.0%20net%20lot%20open%7CHedging%20%280%25%20Hedged%20Margin%29%3A%3A%243%2C617%20margin%20%20%203x3%20free%20%2B%201%20uncovered%7CHedging%20%2850%25%20%3D%20Largest%20Leg%29%3A%3A%2414%2C467%20margin%20%20%20Charges%20max%284%2C3%29%20%3D%204L%7CHedging%20%28100%25%20Gross%20Margin%29%3A%3A%2425%2C317%20margin%20%20%20Charges%204%20%2B%203%20%3D%207%20Lots&metrics=0%25%20HEDGE%20TRAP%3A%3ARollover%20Gap%3A%3A20-pip%20spread%20eats%20Equity!%7CSWAP%20ON%20HEDGE%3A%3ANegative%20Net%3A%3ALong%20Swap%20%2B%20Short%20Swap%20%3C%200!%7CEXCHANGE%20RULE%3A%3A100%25%20Netting%3A%3ACME%20%2F%20NYSE%20%2F%20MOEX%20standard%7CLINEAGE%20KEY%3A%3APOS_IDENTIFIER%3A%3AImmutable%20lifecycle%20ID)

## 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](/calculators/terminal-margin-var-es-calculator) and explore MQL5 async patterns in the [MT5, cTrader & Bridge Topic Hub](/topics/mt5-ctrader-bridge-dealer-architecture).

- [OTC FX Last-Look Hold Windows: FX Global Code Principle 17 & Firm Liquidity TCA](/reports/otc-fx-last-look-hold-windows-symmetric-vs-asymmetric-lp-rejections)

## 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.


## Source URLs

- https://www.mql5.com/en/articles/2299
- https://www.nfa.futures.org/rulebooksql/rules.aspx?Section=4&RuleID=RULE%202-43
- https://www.mql5.com/en/docs/constants/tradingconstants/dealproperties

## Citation

- APA: Marcus Thorne, CQF. (2026). 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
- Canonical article: [MT5 Netting vs Hedging Position Ledgers: Orders, Deals, CloseBy & Margin Math](https://terminalledgerdesk.com/reports/mt5-netting-vs-hedging-account-position-ledger-margin-recalculation)
- Site research index: [Terminal Ledger Desk](https://terminalledgerdesk.com/llms-full.txt)
