Retrieving the Most Recent Closed Trade from Account History
Summary
This programming note explains how an MQL5 expert advisor can retrieve recent deal information from account history without looping through every record. It selects history from a chosen start time through the current time, gets the final deal ticket, and reads its profit and trade direction for display. The example also describes retrieving the symbol and showing the deal count and ticket on the chart.
The history start time is configurable, and selecting from midnight limits the lookup to the current day; selecting from the beginning of the account retrieves the full history. The example proposes calling the routine on every tick or once per bar. It does not discuss handling an empty history selection, distinguishing closing deals from other deal types, or validating the symbol lookup, so those details require care in practical use.
Key ideas
- The example selects account history over a chosen time range and reads the final deal ticket.
- It retrieves the deal’s profit and type for display, along with history-related information.
- A midnight start time limits the lookup to the current day, while a zero start time selects full history.
- The routine can be called on every tick or once per bar.
- The example does not explain safeguards for empty history or filtering specifically for closing deals.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.