Quick Answer
In MetaTrader 5, a netting account keeps one combined position per symbol, while a hedging account can keep multiple separate positions on the same symbol, including positions in opposite directions. That difference affects how an Expert Advisor identifies, adds to, closes, and reverses trades.
Before running an EA, detect the account's margin mode with AccountInfoInteger(ACCOUNT_MARGIN_MODE) and decide what the strategy should do in each supported mode. Code that assumes each trade is an independent position can behave differently on a netting account, where activity from more than one EA or a manual trade may affect the same symbol position.
Key Facts
- Positions per symbol: Netting keeps one combined position at a time; hedging can keep several separate positions open.
- Same-direction deal: On netting, it changes the symbol's existing net exposure. On hedging, it can create another separate position.
- Opposite-direction deal: On netting, it reduces, closes, or reverses exposure depending on size. On hedging, it can open a separate position in the other direction.
- Position identification: Netting centers on symbol-level exposure; hedging often requires the EA to identify a specific position ticket.
- EA design concern: In either mode, avoid assuming every position on a symbol belongs exclusively to one strategy; filter and manage positions intentionally.
MetaQuotes documents the account modes in its Account Properties reference. Its PositionSelect() reference describes the one-position-per-symbol behavior for netting and the multiple-position behavior for hedging.
What Netting Means in Practice
On a netting account, deals for the same symbol contribute to one position. A later buy can increase a long position or reduce a short position; a sell can reduce a long position or increase a short one. An opposite deal can flatten or reverse the net exposure depending on its volume.
This has an important implication for EAs: the terminal does not maintain separate simultaneous positions for every strategy on that symbol in netting mode. If a manual trade and multiple EAs trade the same symbol, they may all affect the same net position. A magic number can label orders and deals, but it does not turn one net position into separate independently managed position objects.
If a strategy expects to manage its own independent long and short tickets, either adapt its rules to net exposure or require a hedging account. Do not assume the account mode based on the broker name; query it at runtime.
What Hedging Means in Practice
On a hedging account, more than one position can be open for the same symbol. The positions can have different volumes, entry prices, stop levels, and directions. This supports workflows that manage entries separately, but it also means an EA must identify exactly which position it intends to inspect or modify.
Avoid assuming that “the position for this symbol” is always the EA's own trade. When iterating positions, filter by the symbol and the EA's magic number, and retain or select the relevant ticket before applying a change. If you have multiple positions from the same strategy, define whether the rule acts on one ticket, every matching ticket, or the combined exposure.
Detect the Account Mode in MQL5
Use the account's margin mode rather than inferring the behavior from the number of open trades:
ENUM_ACCOUNT_MARGIN_MODE marginMode =
(ENUM_ACCOUNT_MARGIN_MODE)AccountInfoInteger(ACCOUNT_MARGIN_MODE);
bool isHedging = (marginMode == ACCOUNT_MARGIN_MODE_RETAIL_HEDGING);
bool isNetting = (marginMode == ACCOUNT_MARGIN_MODE_RETAIL_NETTING ||
marginMode == ACCOUNT_MARGIN_MODE_EXCHANGE);
if(!isHedging && !isNetting)
{
Print("Unsupported account margin mode: ", (int)marginMode);
return INIT_FAILED;
}
This check classifies the retail hedging mode and the two netting-style modes. Keep the branch explicit so the EA fails safely if it encounters a mode it was not designed to handle. The MQL5 AccountInfoInteger() documentation describes reading integer account properties.
Decide How the EA Should Behave
Before enabling trading, answer these questions for each mode:
- Can the EA open another position while one already exists? Specify whether the intended behavior is one position, scaling in, or independent entries.
- What should an opposite signal do? Close first, reduce exposure, reverse, or ignore it? Test the chosen behavior with the actual account mode.
- Which trades belong to this EA? Use a stable magic number and filter by symbol. On hedging accounts, identify individual tickets when acting on individual positions.
- Can another EA or a manual trade touch this symbol? On netting accounts, shared symbol exposure can make ownership and stop management more complex.
- What happens after a restart? Re-read current positions and reconcile them with the EA's expected state; do not rely only on an in-memory flag.
- How are partial exits handled? Verify the target platform operation and resulting exposure under the account's position model.
These are strategy rules, not just API details. Two EAs can compile successfully and still produce different exposure if one expects hedging while the other is operating on a netting account.
Common EA Mistakes
Treating PositionSelect(_Symbol) as ownership
Selecting by symbol tells the program about a position on that symbol; it does not prove that the position belongs only to the current EA. Check its magic number and other identifiers before modifying it. In hedging mode, enumerate and select the intended ticket when multiple positions exist.
Expecting opposite orders to create separate trades on netting
An opposite deal on a netting account changes the existing net exposure. It is not a separate opposing position. If the strategy depends on holding long and short trades independently, make that account requirement clear or redesign the logic.
Closing every position on a symbol
A symbol-wide close can affect trades beyond the EA's intended position, particularly in shared-symbol workflows. Decide whether the operation should target a ticket, a matching magic number, or the full symbol exposure, and check the result.
Testing only on one account mode
If the EA claims to support both, test entries, reversals, partial exits, restarts, and interactions with an existing position on both a netting and a hedging demo account. A backtest on one mode does not establish correct behavior on the other.
For MQL5 position iteration and magic-number filtering, see filter positions by magic number. For handling Pine opposite signals, read Pine Script strategy close in MQL5.
A Practical Test Matrix
- First buy signal: Confirm that netting creates the intended long exposure and hedging creates the intended ticket.
- Repeated buy signal: Confirm exposure does not grow unless pyramiding is intended; on hedging, check that an extra ticket is not created accidentally.
- Opposite sell signal: Confirm netting reduces, closes, or reverses as specified; on hedging, confirm only the intended ticket or tickets are affected.
- Manual position already open: Confirm the EA follows its ownership policy in netting and leaves unrelated tickets untouched in hedging.
- EA restart: Confirm net exposure or each relevant ticket is reconciled with the strategy's persisted state.
- Partial exit: Confirm the remaining net volume and stop behavior are correct, or only the intended hedging tickets are reduced.
Also check the server return code after each trade request and log the account mode, symbol, magic number, ticket, requested volume, and resulting position state. See MQL5 trade return codes for interpreting server responses.
Which Account Mode Should You Use?
Neither mode is universally better. Netting is suitable when the strategy is designed around one net exposure per symbol. Hedging is useful when separate positions on the same symbol are an intentional part of the workflow. Your broker determines which account modes are available, and the account's conditions and rules can vary.
Choose the mode that matches the EA's position model, then test that exact configuration. If you are converting a Pine strategy, be explicit about pyramiding, opposite entries, and position sizing: the target account can change how those rules translate. The Pine Script to MQL5 guide explains the broader conversion workflow, and the lot-size calculation guide covers volume and risk inputs.
Frequently Asked Questions
Related Guides
- Filter MQL5 positions by magic number
- Pine Script strategy close in MQL5
- MQL5 lot-size calculation
- MQL5 daily loss limit
- Trading bot checklist before going live
This article is educational and is not financial advice. Automated trading carries risk, including the loss of capital. Test account-mode behavior in a controlled environment and review every trade before considering live use.