Skip to content
All library documents

MetaTrader 5 Trade Requests, Server Events, and State Tracking

Article MQL5 articles

Summary

This article explains how a MetaTrader 5 trade request moves from the terminal to the server, becomes an order, and may produce deals that change positions. It distinguishes request validation from execution: a successful basic check or an accepted request does not guarantee a completed trade. It also describes server-side checks, order cancellation and expiration, and how order, position, deal, and history changes generate trade events.

Because processing and event delivery are asynchronous, a single request can lead to multiple changes, while event messages may arrive after an order has already moved to history. The article illustrates this with a partially filled pending order, where individual deals and order-volume updates produce several events. For reliable EA handling, it recommends keeping a snapshot of the account’s orders, positions, and history, then comparing it with the current state when OnTrade runs. The method consumes terminal resources according to the amount of history loaded, and event counts alone cannot reliably identify what changed.

Key ideas

  • OrderSend returning success indicates that a request passed a basic check, not that the requested trade executed.
  • A single order can generate multiple deals and trade events as it is partially filled or moved to history.
  • Trade events and account-state updates arrive asynchronously, so event order does not map one-to-one to requests.
  • An Expert Advisor can identify account changes by comparing current orders, positions, and history with a saved prior state.
  • Loading deeper trade history improves the comparison scope but uses more terminal and computer resources.

Tags

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