Skip to content
All library documents

Reconstructing Historical Positions from Deals to Plot Profit and Loss

Article MQL5 articles

Summary

The article describes how to reconstruct closed positions in MetaTrader 5, where historical positions are not directly exposed through the same functions used for open positions. It uses deal history as the source: each deal carries a position identifier, allowing deals with a shared identifier to be grouped into a position. Custom deal, position, and historical-position-list classes organize properties such as entry and exit times, prices, volume, and financial results.

The resulting position history feeds an indicator that estimates each position’s profit relative to bar prices while the position existed, then aggregates those values into a chart with positive and negative regions. The method demonstrates a practical way to inspect account history visually, but the author says the example does not handle every detail needed for fully accurate position reconstruction. Its plotted measure depends on the chosen price reference and settings, so it should not be treated as a complete accounting or performance analysis without further validation.

Key ideas

  • Historical deals can be grouped into positions by matching their position identifiers.
  • Custom classes can store deal properties and assemble the entry, exit, and other attributes of each historical position.
  • An indicator can estimate and aggregate position profit relative to bar prices over each position’s lifetime.
  • The example provides a visual history-analysis method rather than a trading strategy.
  • The reconstruction is explicitly incomplete for some accuracy requirements and may need extension.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.