Using Deal History to Track Position Entries and Properties in MQL5
Summary
This MQL5 cookbook chapter extends an Expert Advisor so it can retrieve position details that are not available from current position properties alone. By selecting the account's deal history for a position, the program can find the first and most recent deal prices and count the associated deals. These details matter when position volume changes over time, since the current average position price does not reveal the original entry or last addition.
The article organizes position and symbol data into structures, then uses helper functions to retrieve and display those properties. It also adds volume increases when new entry signals occur while a position is already open, alongside configurable trade settings and an information panel. A Strategy Tester optimization and tests on several currency pairs are shown, but the article does not provide enough detail to establish that the parameter set generalizes; it presents a development example rather than a validated strategy. The history-based functions are most relevant to systems that scale position volume or apply money management based on position changes.
Key ideas
- Current position fields do not provide every useful price associated with a position's deal history.
- Selecting deals linked to a position can reveal its first entry price, last deal price, and deal count.
- Structures can group position and symbol properties to simplify access and code organization.
- History-based property functions are especially useful when a strategy changes position volume over time.
- The optimization results shown are examples and do not demonstrate that the settings will generalize.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.