Forex & EA basics
Close By in MT5: match two opposite positions
On a hedging account, a buy and a sell can coexist on the same symbol. Close By is a specific way to close opposite positions against each other. Opening an opposite trade and leaving both positions active is a different operation.
Identify both tickets
The CTrade PositionCloseBy interface takes two position tickets. Confirm that the account and symbol support this operation, that directions are opposite and that both positions belong to the intended strategy. Never select a pair only because the symbol names match.
Consider unequal sizes
In a hypothetical pair of 0.05 lots and 0.03 lots, matching the smaller amount leaves exposure of 0.02 lots. Plan how the remaining position is managed. Inspect the resulting deals rather than assuming two original tickets imply two equal-sized closures.
Compare the complete cost
A useful demo comparison records the same starting positions, closure method, execution prices and all fees. Avoid judging from one deal row alone: paired closure accounting can distribute the reported result differently from two separate market closures.
Make the intent visible
A custom button or EA rule can name the two tickets and show the expected remainder before execution. For an AI-assisted change, ask for account-mode validation and result logging first. The goal is predictable position handling, not a claim that every broker or trade benefits from the same closure method.
Back to top












