Handling Position Closures Across Netting and Hedging Accounts
Summary
This article continues the construction of an MQL5 order-handling class for a chart-operated trading tool and a future market replay simulator. Its main lesson is that closing a position must account for the account model. In a hedging account, an opposite-side market order can open a separate position unless the close request identifies the position ticket. In a netting account, an opposite trade reduces or closes the existing exposure and can reverse it if the traded volume is larger.
The example builds a close request from the selected position's symbol, direction, ticket, and volume, then checks and sends the request to the trading server. The author frames the code as one module in a larger system intended to share components between live trading and simulation. The article focuses on order mechanics and software structure, not on a trading strategy or evidence of execution quality.
Key ideas
- Netting and hedging accounts handle opposite-side orders differently.
- In a hedging account, a close request should identify the position ticket to avoid opening a separate trade.
- In a netting account, an opposite trade can reduce exposure, close it, or reverse it depending on volume.
- The example validates an order request before sending it to the server.
- The class is part of a modular trading and replay-simulation project.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.