Skip to content
← Learning hub
Engineering / Tutorial

Netting or hedging? Test the MT5 account model first

See how MetaTrader 5 netting and hedging accounts represent same-symbol trades, and add account-mode checks to strategy acceptance tests.

Edge Quant editorial · 2026-11-16 · About 7 minutes

An Expert Advisor can submit valid orders and still manage the wrong exposure if it assumes every account represents positions the same way. In MetaTrader 5, netting and hedging modes change how deals on one symbol become positions.

Published 16 November 2026. All position sizes below are hypothetical illustrations, not account observations, a trading recommendation or an Edge Quant test.

Separate orders, deals and positions

An order requests an operation. A deal records an execution. A position represents current exposure under the account’s accounting model. Code that counts orders or deals and treats that count as the number of open positions can therefore misread the account, especially after partial fills, reversals or multiple entries.

MetaQuotes documents two common position-accounting models. A netting account has at most one position per symbol; further deals contribute to that position. A hedging account can keep multiple positions on the same symbol, including positions in opposite directions. MT5 also has an exchange margin mode; inspect the actual account property instead of inferring behavior from the broker or instrument name.

One hypothetical sequence, two representations

Hypothetical example: an EA buys 1.0 lot of a symbol and later sells 0.4 lot of the same symbol. In a netting model, the second deal reduces the long exposure to 0.6 lot, assuming those volumes are expressed in the same instrument units and both deals execute as stated. In a hedging model, the account may instead show a 1.0-lot long position and a separate 0.4-lot short position. Net directional exposure is 0.6 lot, but gross open exposure is 1.4 lots and the two positions can have separate tickets and protective levels.

That distinction changes what a strategy means. A rule to “close the trade” might mean reducing the symbol’s net position, closing a specific ticket, or removing all positions on the symbol. Those operations are not interchangeable. Margin, financing, commissions, stop-loss handling and broker rules can also depend on the instrument and account.

Detect the model at runtime

The MQL5 reference exposes ACCOUNT_MARGIN_MODE through account information, with values for retail netting, exchange and retail hedging. Read it during initialization, log the value and define explicitly which modes the EA supports. If the system requires one-ticket-per-entry behavior, fail safely or show a clear unsupported-mode message on a netting account.

Do not infer hedging from the ability to place an opposite order. Confirm the resulting positions after execution. For production code, inspect the trade result, query the current position state and handle asynchronous state changes or partial fills where the chosen execution path permits them.

Design the position-management contract

Before coding, define whether the strategy owns the whole symbol position or only its own strategy allocation. On a shared netting account, another EA or manual trade can change the single net position. If independent strategies trade the same symbol, a simple per-symbol close can accidentally reduce exposure that another component intended to keep. A magic number on a deal does not create separate net positions by itself.

On hedging accounts, define whether exits target one ticket, a tagged set of tickets or every position for the symbol. Verify that the close method is valid for the account model. MetaQuotes notes that partial-close behavior and ticket selection have mode-specific implications; read the trade-method return status and then confirm the resulting volume rather than treating a successful function call as proof that the intended exposure remains.

A compact acceptance-test matrix

  1. Record the account margin mode at startup and test supported and unsupported modes.
  2. Open, add to, reduce and reverse a same-symbol position; compare deals with resulting positions.
  3. On hedging mode, test simultaneous long and short positions and ticket-specific exits.
  4. Test partial fills, rejected requests and existing manual or other-EA exposure.
  5. Confirm stop-loss, take-profit, margin and financing behavior with the broker’s symbol specification.
  6. Restart the EA and reconstruct ownership from actual account state, not an assumed in-memory trade list.

The practical takeaway

Netting and hedging accounts can show different position structures for the same sequence of intended trades. Make the EA identify its account mode, specify who owns symbol-level exposure and test closes against live position state. A backtest that models one representation does not establish correct behavior on the other.

Primary references

References reviewed 16 November 2026. Original exercises and project-specific observations are identified separately.

Keep exploring

Review an MQL5 source file ↗

Educational engineering and research guidance. Examples do not establish a profitable or live-ready trading strategy.