Hedging and netting accounts
Understand hedging, netting, and exchange account behavior, including strategy magic numbers, trade tickets, and how position management differs.
Last updated: 2026-10-07
Your broker sets the account mode when it creates the account, and PineHook works with either hedging or netting on MetaTrader 5 and cTrader. If MT5 labels the account as EXCHANGE, treat it as netting throughout this guide because it follows the same one-position-per-symbol rule.
Hedging and netting at a glance#
| Behavior | Hedging | Netting and exchange |
|---|---|---|
| Positions on one symbol | Each entry opens a separate position. | All orders combine into one position. Two 0.1-lot EURUSD buys become one 0.2-lot position. |
| Opposite orders | A sell can open beside a buy. Allow Hedging off skips a new entry while the symbol has an opposite position or order. | A sell reduces, closes, or reverses an existing buy, regardless of Allow Hedging. |
| Stops and targets | Every position has its own stop and target. | The combined position has one broker stop and target. |
| Strategy separation | Different strategies can hold separate positions on the same symbol. | Use one strategy per account. All of its orders for a symbol change the same position. |
You will see these modes under different names depending on the platform. MT5 uses HEDGING, NETTING, and EXCHANGE, while cTrader usually shows Hedged or Netted.
Turning off Allow Hedging stops PineHook from opening an entry while a position or pending order on the same symbol points the other way, which helps when your broker or prop firm forbids holding both sides. It only matters on hedging accounts, and hedging entry protection explains how it works and how to override it for a single alert.
Choose what the alert manages#
On a hedging account, an alert can manage a strategy or one position or pending order within it. Magic numbers group them by strategy, while PineHook tickets target one specific position or order in that group. A netting or exchange account should run one strategy per account and manage the combined broker position by symbol, so tickets are not needed there.
| Alert | Account type | What it manages |
|---|---|---|
modify,EURUSD,ticket=eur-long-001 | Hedging | One position |
modify,EURUSD,magic=1001 | Hedging | Every matching position in Strategy 1001 |
modify,EURUSD | Netting or exchange | The combined EURUSD position, using Default Magic |
closeall,EURUSD,magic=ALL | Either | Every strategy that the command permits on EURUSD |
| A supported command without a symbol | Either | The command's documented account-wide scope |
Magic numbers identify strategies#
On a hedging account, give each strategy a different magic= value so its management alerts leave the others alone. On a netting or exchange account, keep one strategy per broker account and omit magic= to use the license's Default Magic.
LICENSE,buy,EURUSD,size_lots=0.1,magic=1001
MT5 stores the value in its native magic-number field. Since cTrader has no equivalent field, PineHook writes the value into the label of managed positions and pending orders, which keeps the alert syntax the same on both platforms and through a Trade Copier.
| Value | Meaning |
|---|---|
| Omitted | Use the license's Default Magic. |
magic=0 | Select the zero-magic group. On MT5 this can include manual positions and orders, and on cTrader it can include unlabeled manual positions and orders, so use it carefully. |
magic=N | Select that positive-numbered strategy. |
magic=ALL | Select every strategy allowed by a supported management command. It cannot open a position or place a pending order. |
Your Default Magic is 0 unless you change it in your license settings. MT5 also gives trades you open by hand a magic number of 0, so while your Default Magic is 0, an alert without magic= can reach your manual trades, and a non-zero Default Magic keeps them apart. A magic number is a whole number from 0 to 2,147,483,647, and ALL is the only wildcard, so -1 is rejected.
Your plan also limits how many magic numbers can trade one symbol on a license at the same time: 2 on Trial and Standard, 5 on Pro and 10 on Premium. An entry from an extra magic number is skipped with Skipped: Position Limit, and a strategy's slot frees once it has no open position or pending order left on that symbol. Several tickets under one magic number count as a single strategy.
On a hedging account, a command that includes magic= but no ticket= applies to every matching position and pending order in that strategy, subject to the command's symbol, direction, and other filters. Add ticket= to target only the position or pending order associated with that ticket.
PineHook tickets identify positions and pending orders on hedging accounts#
Use PineHook tickets only on hedging accounts, where the broker can hold several positions or pending orders for the same symbol. A ticket identifies one of those positions or orders on a license and remains separate from the native order, position, and deal numbers assigned by MT5, cTrader, or the broker. You choose the ticket yourself, using any naming scheme that makes sense for your strategy, such as eur-long-001, breakout_2, or London.Open.
LICENSE,buy,EURUSD,size_lots=0.1,magic=1001,ticket=eur-long-001
LICENSE,closelong,EURUSD,ticket=eur-long-001
If a Trade Copier sends the position to several hedging accounts, it uses the same PineHook ticket at each destination.
- A ticket must contain 1 to 32 characters and start with a letter or number. After that, you may use letters, numbers, dots, underscores, and hyphens. Ticket names are case-sensitive, so
EUR-longandeur-longare different tickets. - Spaces and other special characters are not allowed. This includes commas, semicolons, slashes, backslashes, colons, and symbols such as
@,#,$,%,&, and?. ThePH-prefix is also unavailable because PineHook reserves it for generated tickets. - A command can contain only one
ticket=value. To manage several chosen positions, send one command for each ticket. To manage every matching position in a strategy, usemagic=withoutticket=. On compound commands,new_ticket=defines the replacement and does not target a second existing position. - If an entry omits
ticket=, PineHook generates one and shows it in Signal Logs. MT5 also prints it in the Experts tab, while cTrader stores it in the position or pending-order comment. TradingView cannot read this value after sending an alert, so supply your own when the script must manage that position or order later. - On MT5, tickets need the updated EA. A ticketed alert that arrives while the EA is offline is held and handled like any other missed alert when it reconnects.
- Ordinary entry tickets are single-use, even after the position closes or order is cancelled. The exception is
setposition, where a verified ticket identifies a reusable group that survives flattening, reopening, and reversal. Its increases may create several broker positions under the same group ticket, and without a ticket it manages every position in the exact symbol-and-magic group.
PineHook resolves a ticket within the current user, license, and linked broker account. If the same alert includes a symbol, direction, or numeric magic, those values must match the saved position or order. Using ticket= without magic= is valid because PineHook uses its saved magic.
For ordinary existing-position or order management, PineHook refuses an unknown ticket, a closed position or cancelled order, conflicting details, or an ambiguous match. It will not redirect the command to another ticket or the whole strategy. setposition uses its verified group rules to create a new group or reopen a flat persistent group with the same ticket.
Replace one position or pending order#
On a hedging account, a compound command can close one position and open its replacement, or cancel one pending order and place a new one. Here, ticket= selects the existing position or order and new_ticket= defines the replacement. On a netting or exchange account, omit both parameters and let the command manage the symbol's combined position.
new_ticket= works with these commands:
| Command group | Commands |
|---|---|
| Close and open | closelongopenlong, closelongopenshort, closeshortopenlong, closeshortopenshort, closelongshortopenlong, closelongshortopenshort |
| Cancel and replace | cancellongbuystop, cancellongbuylimit, cancelshortsellstop, cancelshortselllimit |
For example, Strategy 6 could hold two EURUSD longs named ticket=3 and ticket=6. This alert closes only ticket 6, opens ticket 7, and leaves ticket 3 alone:
LICENSE,closelongopenlong,EURUSD,magic=6,ticket=6,new_ticket=7,size_lots=0.1
The same pattern applies to pending orders:
LICENSE,cancellongbuystop,EURUSD,magic=6,ticket=old-entry,new_ticket=next-entry,size_lots=0.1,price=1.0850
The two ticket values must differ, and new_ticket must never have been used before. If you omit it, PineHook generates one and shows it in Signal Logs, but a TradingView script cannot look up that value later. Supply your own when later alerts must manage the replacement; a Trade Copier will then give every destination the same new PineHook ticket.
closecancelall is a sweep command. It closes every position and cancels every pending order that matches its symbol and magic scope, so it does not accept ticket=.
| Alert scope | What closecancelall affects |
|---|---|
Symbol and magic=N | That strategy's positions and pending orders on the specified symbol. |
Symbol and magic=ALL | Every position and pending order on the specified symbol, including those created manually or by other software. |
Symbol without magic= | Positions and pending orders that use the license's Default Magic on that symbol. |
magic=N without a symbol | That strategy's positions and pending orders across all symbols. |
No symbol and no magic= | Every position and pending order on the linked account, across all symbols and magic numbers. |
What changes on netting accounts#
On a netting or exchange account, buys add to the single position and sells subtract from it. If EURUSD is 4 lots long, a 2-lot sell leaves 2 lots long, a 4-lot sell closes the position, and a 6-lot sell leaves 2 lots short.
Run one strategy per netting or exchange account and manage its combined position by symbol. You do not need ticket= or new_ticket= on these accounts, and you can ignore any generated PineHook ticket shown in Signal Logs.
On a netting or exchange account, setposition sets the size of the symbol's single combined position, whatever Magic Number the alert carries. If two strategies both trade EURUSD there, target=2 leaves the whole account 2 lots long on EURUSD, not 2 lots for one strategy.
If an alert includes ticket= or new_ticket= for a netting or exchange account, PineHook rejects the entire alert before it is queued. The rejection appears in Signal Logs and the Rejected Signals section, where the message explains that the ticket ID must be removed and the combined position managed by symbol. PineHook never strips the ticket and continues with a wider command.
Account-wide commands#
closeall, closecancelall, closealleaoff, closecancelalleaoff, closeallprofit, closeallloss, cancelall, and clearqueue can all be sent without a symbol or magic= filter. In that form, the command runs across every symbol and magic number while still applying its own rules, such as the profit test on closeallprofit. Adding magic=N narrows it to that strategy on every symbol. The broker-side commands may therefore affect positions or pending orders created manually or by other software. clearqueue is different because it only removes PineHook alerts waiting in the server-side delay queue; it never touches broker positions or pending orders. See the Default Mode command reference for each command's scope.
Recommended setup#
| Goal | Account setup | Alert scope |
|---|---|---|
| One strategy trades the account | Hedging, netting, or exchange | Omit magic= to use Default Magic |
| Several independent strategies trade one symbol | Hedging | Give each strategy a unique magic=N |
| Manage one position inside a strategy | Hedging | Give the entry a unique ticket= |
| Manage a combined net position | Netting or exchange | Omit tickets and manage it by symbol |
| Run several strategies with a netting broker | Separate broker accounts and licenses | Run one strategy per account |