Netting and hedging are the MetaTrader 5 (MT5) position accounting systems, set by the broker per account. Netting keeps one position per symbol; an opposite deal can reduce, close or reverse it. On hedging, a new opening order can create a separate opposite position. A closing or partial-closing deal instead reduces or removes the selected position.[1][16] Check both the account type and the requested action when interpreting an alert.
The accounting system belongs to the broker account, not to TradingView or the PineConnector EA. Check it before you automate reversals or run several strategies on one account. Netting and hedging sit beside lots, margin and order types in the trading mechanics library.

Netting vs hedging at a glance
Scroll horizontally to read every column.
| Question | Netting account | Hedging account |
|---|---|---|
| Positions per symbol | One common position | Several, including a buy and a sell at once |
| A new opening order in the same direction | Adds volume; the open price becomes a volume-weighted average | Opens another position; existing positions do not change |
| A new opening order in the opposite direction | Reduces, closes or reverses the one position | Opens an opposite position; both stay open |
| How a position closes | An opposite deal of the same volume | Close Position on that position, or Close By against an opposite one |
| Reversal in one deal | Yes, when the opposite deal is larger than the position | No; closing the position and opening an opposite one are separate operations |
| Stop Loss and Take Profit | Increases/reversals use the latest order’s levels; partial closes leave levels unchanged | Each position keeps its own levels, except under the FIFO rule |
| FIFO closing rule | Not available | The broker can enable it |
MQL5 ACCOUNT_MARGIN_MODE
|
Retail netting | Retail hedging |
The rows follow MetaQuotes' Basic Principles and Executing Trades help pages and the MQL5 Account Properties reference, as of 25 September 2026.[1][2][3] MetaQuotes describes the hedging system as similar to the one used in MetaTrader 4,[4] which matters if you are moving from MetaTrader 4 to MetaTrader 5.
What rule does each system apply to a new deal?
Netting: new position volume = current volume + deal volume, with buys counted as positive and sells as negative
The signed form is this page's notation for MetaQuotes' rule. A same-direction deal "increases the volume of this position". An opposite deal decreases the volume, closes the position when the volumes are equal, or reverses it when the deal is larger.[1] A result of zero means the position closed. A result with the opposite sign means it reversed, and the new position's volume is the part of the deal left after closing. A triggered pending order nets in the same way as a market order.[1]
Netting open price after adding volume = (P1 × V1 + P2 × V2) ÷ (V1 + V2)
P is each deal's price and V its volume in lots. MetaQuotes gives this weighted-average formula for a second deal in the same direction on a netting account.[2] Its wording on the open price after an opposite deal is brief, so read the price on the Trade tab after a reduction or reversal instead of assuming it.
Hedging distinguishes opening orders from deals that close a selected position
A hedging account can hold separate positions from new opening orders. This does not mean every deal adds a position: MetaQuotes distinguishes entry, exit, reversal and close-by deals.[16] A partial close reduces the selected position; a full close removes it. Use the position ticket when modifying or closing a hedging position.[2][4]
The MQL5 Position Properties reference adds one detail for netting. When a position reverses in a single deal, its POSITION_IDENTIFIER stays the same while POSITION_TICKET changes to the ticket of the order that reversed it. The same page says "Position reversal is not provided in hedging mode."[5]
Worked example: the same four deals on each account
Illustrative example, not a recommendation. Four EURUSD opening orders fill in the listed sequence on netting and hedging accounts. None is a hedging Close Position request. The prices are illustrative fills; spread, commission and swap are left out.
| Deal | Netting account | Hedging account |
|---|---|---|
| 1. Buy 1.00 lot at 1.10000 | One buy of 1.00 lot at 1.10000 | Position A: buy 1.00 lot at 1.10000 |
| 2. Buy 0.50 lot at 1.10300 | One buy of 1.50 lots at 1.10100 | A, plus position B: buy 0.50 lot at 1.10300 |
| 3. Sell 0.50 lot at 1.10400 | One buy of 1.00 lot | A and B, plus position C: sell 0.50 lot |
| 4. Sell 2.00 lots at 1.10200 | Reversed: one sell of 1.00 lot | A, B and C, plus position D: sell 2.00 lots |
| After deal 4 | 1 position, 1.00 lot open, net short 1.00 lot | 4 positions, 4.00 lots open, net short 1.00 lot |
- Deal 2 on netting. (1.10000 × 1.00 + 1.10300 × 0.50) ÷ (1.00 + 0.50) = (1.10000 + 0.55150) ÷ 1.50 = 1.65150 ÷ 1.50 = 1.10100.
- Deal 3. On netting, 1.50 − 0.50 = 1.00 lot, still a buy. On hedging, the net volume is also 1.00 + 0.50 − 0.50 = 1.00 lot long, but it is spread across three open positions.
- Deal 4. On netting, 1.00 − 2.00 = −1.00: the 2.00-lot sell closes the 1.00-lot buy and leaves a 1.00-lot sell. On hedging, buys total 1.00 + 0.50 = 1.50 lots and sells 0.50 + 2.00 = 2.50 lots. Net exposure is 1.50 − 2.50 = −1.00 lot, as on netting, but 1.00 + 0.50 + 0.50 + 2.00 = 4.00 lots stay open in four positions.
- Stops on netting. Suppose deal 1's order set a stop loss at 1.09500 and deal 2's order set one at 1.09800. MetaQuotes' netting rule replaces the levels, so the whole 1.50-lot position now has its stop at 1.09800. Had deal 2's order carried zero stop values, the position's Stop Loss and Take Profit would have been deleted.[1]
- Stops after deals 3 and 4. Deal 3 is a partial close, which leaves the levels unchanged. Deal 4 reverses the position, so the levels come from deal 4's own order.[1] On a hedging account without the FIFO rule, A keeps 1.09500 and B keeps 1.09800.

Why does the account type change what a TradingView alert does?
A TradingView strategy already keeps a single net position. Pine strategies "can only have positions open in one direction at a time", according to TradingView's strategy FAQ.[6] When strategy.entry() meets an open position in the opposite direction, it "automatically adds the position’s size to the new order’s size". TradingView's example reverses a 15-share long into a 5-share short with one 20-share transaction.[7] The strategy.entry() and strategy.exit() guide covers that logic in Pine Script v6.
The alert then describes that one simulated order. The {{strategy.order.contracts}} placeholder "returns the number of contracts of the executed order",[8] so a reversal alert can carry the combined quantity. PineConnector's strategy-alert guide says that quantity is "not automatically MetaTrader lots" and lists reversal quantities among the things to check before mapping it.[9] What the MT5 account does with the resulting order depends on its accounting system and on the EA's settings.
Illustrative example, not a recommendation. The receiving account holds a 1.00-lot EURUSD buy. The strategy's reversal alert sends LicenseID,sell,EURUSD,vol_lots=2,sl_pips=20 from the TradingView alert's Message field, after the trader mapped 2 contracts to 2.00 lots. Assume Pyramiding lets the entry through.
- Netting account, Close on Reverse Off: MT5 nets the 2.00-lot sell against the 1.00-lot buy. The result is one sell of 1.00 lot, like the strategy's position.
- Hedging account, Close on Reverse Off: the buy stays open and a 2.00-lot sell opens. Two positions hold 3.00 lots, net short 1.00 lot.
- Hedging account, Close on Reverse On (Hedging): the EA closes the buy and opens the requested 2.00-lot sell. The account is net short 2.00 lots, twice the strategy's short.
- Netting account, Close on Reverse On (Hedging) or On (Netting): not documented for netting accounts; test on demo.
All four outcomes are requested results, and the Close on Reverse behaviour comes from PineConnector's EA settings reference.[10] The message size and the closing method have to describe the same intent. A combined command such as closelongopenshort requests a close and a new entry of the stated size, and PineConnector's syntax reference says a combined message does not ensure that both actions complete.[11] Each stage stays separate: the alert triggering, webhook delivery, PineConnector processing, the EA's order request, the broker's deal and the resulting position.

A demo opened in the terminal without "Use hedge in trading" is a netting account.[12] Test on a demo whose accounting system matches the live account, or the demo result describes a different rule.
Can several strategies share one netting account?
On a netting account, two strategies trading the same symbol share one position. If strategy 1 buys 1.00 lot of EURUSD and strategy 2 then sells 1.00 lot, MetaTrader 5 closes the position and neither strategy holds anything. Strategy labels cannot keep them apart at the broker, because netting allows "only one common position for a symbol".[1] The rule specification guide applies this to a one-position-at-a-time rule.
PineConnector documents two ways to separate strategies, and both describe separate positions. In the multi-strategy guide, a comment= label does the work. The illustrative closing message LicenseID,closelong,EURUSD,comment=strategy 1, pasted in the TradingView alert's Message field, targets "EURUSD buys with that exact comment". Without the comment, a closelong can close the symbol's buys with any comment.[13] Separate Magic Numbers let each EA instance recognise its own positions, and Magic Restriction, on by default, limits management to matching positions.[10] The docs do not describe either method on a netting account that merges both strategies into one position: not documented; test on demo.
On a hedging account the positions stay separate, so a label or a magic number has something to select. PineConnector's multi-strategy example reverses strategy 1 while "the strategy 2 buy stays open", and the page ties that result to the On (Hedging) Close on Reverse option.[13]
Which PineConnector EA settings interact with the account type?
- Close on Reverse. The Close on Reverse setting decides what an opposite signal does to open positions on the symbol. On (Hedging) closes them and opens the new direction, On (Netting) closes them without opening it, and Off leaves them to the other rules, including Pyramiding. The EA reference adds that these are "EA option labels", not a change to the broker account's hedging or netting type.[10]
- Pyramiding. Off (Either 1 Buy OR 1 Sell) lets an existing buy block another buy and a sell. Off (Only 1 Buy AND 1 Sell) allows one buy and one sell on the symbol.[10] A netting account cannot hold that buy and sell as two positions, and the docs do not describe the option on netting accounts.
-
Close commands.
closelongrequests closure of the symbol's buys,closeshortits sells andcloselongshortboth, within the EA's position scope.[11] On a hedging account these select among several positions. On a netting account the symbol has at most one position, and netting-specific handling is not documented. -
Magic Restriction. On is the documented default for Magic Restriction. With it off, the EA can manage the symbol's positions whether this EA, another EA or a manual trade opened them, so a
closelongrequest can affect manual buys too.[10]
After changing Close on Reverse or Pyramiding, PineConnector's best-practice page lists what to test on demo: "A fresh entry, an opposite signal and repeated same-direction signals".[14] Compare each result with the positions on the MT5 Trade tab, not only with the alert log.
How do you check whether an MT5 account is netting or hedging?
- Account details. The broker sets the system for each account.[1] MetaQuotes' 2016 article introducing hedging says the system is "displayed in the terminal window header and the Journal".[4] Check both on your build, and ask the broker when in doubt.
- Opening a demo. The Open an Account dialog's "Use hedge in trading" option opens a hedging demo. Without it, "an account with the netting system will be opened".[12] For a real hedging account, the same MetaQuotes article says to contact your broker.[4]
-
From MQL5.
ACCOUNT_MARGIN_MODEreturnsACCOUNT_MARGIN_MODE_RETAIL_NETTINGorACCOUNT_MARGIN_MODE_RETAIL_HEDGING, withACCOUNT_MARGIN_MODE_EXCHANGEas a third value for exchange markets, andACCOUNT_HEDGE_ALLOWEDreports whether opposite positions on one symbol are allowed.[3] - On a demo Trade tab. MetaQuotes' own illustration uses two 0.5-lot EURUSD buys: netting shows one 1-lot position, hedging shows two positions.[1] Repeating that with the symbol's minimum volume on a demo shows which rule applies.
What goes wrong when the account type is assumed?
- Expecting a sell alert to close a buy on hedging. Without a close command or a closing EA setting, an opposite entry opens a second position and both stay open.[1]
- Expecting labels to separate strategies on netting. One symbol has one position, so opposite strategies offset each other at the broker.[1]
- Losing stops on netting. An add-on order's stop levels replace the position's, and zero values delete them.[1] The EA's Setting input decides whether the stop comes from the message or from EA inputs,[10] so inspect the position's stop after an add-on on demo.
- Treating opposite positions as free. Both hedging positions stay open with their own stop levels. MetaQuotes treats opposite positions on one symbol as "hedged or covered" for margin, and the broker chooses the calculation method.[15] Closing the pair separately pays the spread twice; Close By saves one spread.[2] The margin level and stop-out guide explains used margin.
- Ignoring FIFO. A broker can require first-in, first-out closing, and only on hedging accounts. Closing a symbol's positions in a different order then fails with an error. Setting stop levels on one position also sets the same levels on the symbol's other positions.[2]
Frequently asked questions
What is a hedging account in MT5?
A hedging account in MetaTrader 5 can hold several positions on one symbol, including buys and sells. A new opening order can add a separate position. A deal that fully or partially closes a selected position removes or reduces it instead. Use Close Position for a selected position, or Close By for an eligible opposite pair. The broker sets the accounting system.
What is a netting account?
A netting account keeps one position per symbol. Same-direction deals add volume; opposite deals reduce, close or reverse it. An increase or reversal uses the latest order’s stop levels, and zero values can remove them. A partial close leaves SL/TP unchanged; a full close removes the position and its stops.
What is MT5 position accounting?
MT5 position accounting determines how executed deals affect positions. Netting keeps one common position per symbol. Hedging permits separate positions from opening orders, while closing deals reduce or remove selected positions. The broker sets the system; MQL5 reports retail netting, exchange or retail hedging through ACCOUNT_MARGIN_MODE.
Can I change an MT5 account from netting to hedging?
The broker sets the position accounting system for each MetaTrader 5 account, so a change means asking the broker or opening a different account. For a demo opened in the terminal, tick "Use hedge in trading" to get a hedging account; otherwise the demo is netting. MetaQuotes' 2016 hedging article says to contact your broker for a real hedging account.
Does PineConnector's Close on Reverse setting change my account type?
No. PineConnector's EA settings reference says the Close on Reverse options named Hedging and Netting are EA option labels, not a change to the broker account's hedging or netting type. On (Hedging) closes opposite positions and opens the new direction; On (Netting) closes them without opening it. The MT5 account's own accounting system still applies to every deal.
Reviewed 25 September 2026. Facts were checked against the linked sources on that date. Nothing in this article was tested on a trading account.
Related reading
- Trading mechanics: orders, lots, margin and costs in MT5
- Order types: market, limit and stop orders in MT5
- Margin level, margin call and stop out
- Pine Script strategy.entry() and strategy.exit()
- MT4 vs MT5 for automated trading
Sources
- MetaQuotes – MetaTrader 5 Help: Basic Principles (position accounting system), accessed 25 September 2026.
- MetaQuotes – MetaTrader 5 Help: Executing Trades, accessed 25 September 2026.
- MetaQuotes – MQL5 Reference: Account Properties, accessed 25 September 2026.
- MetaQuotes – MetaTrader 5 features hedging position accounting system (MQL5 article, 21 March 2016), accessed 25 September 2026.
- MetaQuotes – MQL5 Reference: Position Properties, accessed 25 September 2026.
- TradingView – Pine Script User Manual: FAQ, Strategies, accessed 25 September 2026.
- TradingView – Pine Script User Manual: Strategies, reversing positions, accessed 25 September 2026.
- TradingView – Strategy Alerts, accessed 25 September 2026.
- PineConnector – Connect your strategy: strategy order-fill alerts, accessed 25 September 2026.
- PineConnector – EA settings reference: Close on Reverse, Pyramiding and Magic Restriction, accessed 25 September 2026.
- PineConnector – PineConnector Syntax: close, cancel and modify, accessed 25 September 2026.
- MetaQuotes – MetaTrader 5 Help: Open an Account, accessed 25 September 2026.
- PineConnector – Keep strategies separate, accessed 25 September 2026.
- PineConnector – Best Practices & Tips: change one thing at a time, accessed 25 September 2026.
- MetaQuotes – MetaTrader 5 Help: Margin Calculation: Retail Forex, Futures, accessed 25 September 2026.
- MetaQuotes – MQL5 Deal Properties: entry and exit classifications, accessed 25 September 2026.
PineConnector executes the instructions you send it. It does not select trades, manage money, or hold funds. Trading carries risk, and past performance of any strategy does not indicate future results.