Skip to content
All library documents

Exporting and Reconstructing Closed MT5 Position History

Article MQL5 code base

Summary

This document describes an MT5 script that exports closed positions from a retail hedging account to a CSV file for spreadsheet review. Users can limit the export to a date range or leave the default dates to include the full available history. The output reconstructs positions in a consolidated format and includes entry and exit times and prices, direction, volume, symbol, stops and targets, commissions, swaps, profit, profit in points, identifiers, comments, and opening and closing reasons. It also records position duration and a running balance that accumulates prior position results.

For the running balance to follow the correct chronology, the position ordering must be set by closing time. The document limits support to retail hedging accounts and says the CSV is opened by the associated Windows application and saved in the terminal’s files folder. It explains the output and one key ordering dependency, but does not discuss validation, handling of unusual position histories, or performance analysis of the exported results.

Key ideas

  • The script exports closed positions from an MT5 retail hedging account to CSV.
  • Users can export a selected date range or retain default dates for the full history.
  • The export consolidates position details, costs, profit, duration, reasons, comments, and tickets.
  • Its running balance includes profits, swaps, and commissions from earlier closed positions.
  • Positions must be ordered by close time for that balance to reflect chronology.

Tags

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