Skip to content
All library documents

Retrieving the Nth Most Recent Closed Market Trade in MT5

Article MQL5 code base

Summary

The document outlines a MetaTrader 5 expert-advisor utility for retrieving a closed market trade by its position counting backward from the newest trade. An index of zero refers to the latest qualifying trade, while increasing the index selects progressively older trades. The search can be restricted by trading symbol and magic number, allowing an expert advisor to distinguish trades associated with a particular instrument or strategy instance.

The text defines active trades as market orders and excludes pending orders. It offers only a brief description of the utility’s behavior: no implementation details, example output, or discussion of history selection, edge cases, or error handling are provided. It is useful as a narrow automation concept for developers who need to reference earlier closed trades, rather than as a trading strategy or performance analysis.

Key ideas

  • A zero index retrieves the most recent qualifying closed market trade.
  • Larger indices select progressively older trades.
  • The lookup can filter trades by symbol and magic number.
  • The description excludes pending orders and provides no code or discussion of edge cases.

Tags

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