Skip to content
All library documents

MQL5 History Library: Querying Position Data Efficiently

Article MQL5 articles

Summary

This article extends an MQL5 history-management library with helper functions for checking how many records are available and retrieving trade history across progressively wider time ranges. It describes checking the previous day first, then expanding the search by weeks for up to a year, before requesting the full account history if no records were found. The stated aim is to reduce unnecessary history retrieval while still allowing older records to be found.

The article also introduces user-facing functions that expose details of the most recently closed position, including its duration. It explains how focused helpers can keep these queries modular and simple to call from other MQL5 projects. The provided excerpt is incomplete: several position-property functions and their implementation details are omitted, and it offers no performance measurements or tests. The described library retrieves and reports historical data; it does not present a trading strategy or evidence that its approach improves trading results.

Key ideas

  • A helper function can return the record count for deals, orders, positions, or pending orders.
  • History retrieval starts with recent data and expands its time range when no records are found.
  • If the expanding search finds nothing, the described method requests the full account history.
  • Exported utility functions let MQL5 programs query properties of the last closed position.
  • The excerpt does not provide benchmarks or the complete implementation of the position queries.

Tags

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