Skip to content
All library documents

Reconstructing Per-Strategy Balance and Equity from Trade History

Article MQL5 articles

Summary

The article describes an Expert Advisor for plotting balance and equity by trading symbol and ORDER_MAGIC, allowing a user to inspect individual strategies on a hedging account. It reconstructs account history in time segments, adds commissions, swap, and deal profit to balance, and maintains a list of open positions to estimate floating profit for equity. Entry, exit, reversal, partial-close, and close-by deals require different updates to that list.

For open positions, the method retrieves historical bid and ask prices, applies profit calculations appropriate to each symbol, and excludes symbols whose data or conversion into the deposit currency is unavailable. It caches repeated tick lookups to reduce processing time and provides filters for symbols and magic numbers. The article also describes MFE and MAE plots for assessing position-level favorable and adverse movement. The result is a historical analysis tool, not evidence that any strategy is profitable; accuracy depends on available market data, symbol conversion, and the correctness of the accounting logic.

Key ideas

  • Trade results combine deal commission, accumulated swap, and deal profit.
  • Historical equity reconstruction requires tracking open position volume and updating it for exits, reversals, and partial closes.
  • Floating profit can be estimated from historical bid and ask prices using the symbol's calculation rules.
  • Unavailable symbols or missing currency conversions are excluded from the calculations.
  • Caching repeated price requests can reduce the runtime of historical analysis.
  • Filtering by symbol and magic number separates strategy contributions and supports MFE and MAE review.

Tags

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