Detecting Pending Order Triggers with Trade Transaction Events
Summary
This Expert Advisor example shows how to detect when a pending order has executed in MetaTrader. Its event handler watches for a newly added deal transaction and records the associated order ticket. A later tick handler checks whether the order can be selected from trade history, then reads its order type to determine whether it was a buy or sell limit or stop order.
If the history lookup has not succeeded yet, the example retries on subsequent ticks while reporting the attempt and any lookup error. Once the order is found, it clears the search flag; it also stops searching if the order is found but is not one of the pending types being checked. The document describes event-driven order-state handling, not a trading strategy. It does not discuss retry limits, transaction edge cases, or broader execution reliability, so those aspects cannot be assessed from the example.
Key ideas
- A newly added deal transaction can signal that an order may have executed.
- The transaction provides an order ticket that can be used to search trade history.
- The example checks the historical order type to identify pending limit and stop orders.
- It retries the history lookup on later ticks when the order is not yet selectable.
- The example addresses order-state detection, not strategy performance or full execution reliability.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.