Skip to content
All library documents

Handling Trade Events in Automated MQL5 Expert Advisors

Article MQL5 articles

Summary

This article explains how an automated Expert Advisor can respond to trade server changes through MQL5 events. It emphasizes event driven design: rather than repeatedly polling orders and positions with ticks or a timer, the EA should handle relevant platform events and pass updates to a manager class. A message flow diagram is described, though its details are not included in the supplied text.

The article outlines manager functions that clear a deleted pending order ticket, convert pending order state into position state, and refresh position information. It then describes transaction handling for market deals, stop loss or take profit changes, and order removal, using those events to update the manager. The approach is intended to keep the EA and its manager synchronized and permit replacement pending orders after deletion. The discussion is a partial implementation guide rather than a trading strategy or empirical study; code sections and figures are omitted, and some automation functions are deferred to later articles.

Key ideas

  • MQL5 Expert Advisors can react to platform events instead of repeatedly polling orders and positions.
  • OnTradeTransaction can distinguish trade changes and route relevant updates to a manager class.
  • When a pending order is deleted, clearing its stored ticket allows the EA to submit a replacement if needed.
  • Position updates should refresh manager state after deals or changes to stop loss and take profit.

Tags

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