Classifying MQL5 Trading Events for Hedging and Netting Accounts
Summary
This article explains how an MQL5 library can detect and report account trading events. It separates event identification for hedging and netting accounts, using changes in pending order counts, position counts, position volumes, and modification times. These comparisons help distinguish order placement or removal, activation, position opening and closing, and partial volume changes. The article also describes storing the latest event as a persistent code made from flags, so an EA can inspect both the event category and details such as partial execution or closure by stop loss, take profit, or an opposite position.
The implementation adds account-mode detection to the engine, defines event and event-flag enumerations, and demonstrates reporting an event in an EA. Evidence is the described logic and a test interface that displays event names as account activity occurs. The material is primarily a software design tutorial; it does not present trading performance results, and its detection scheme focuses on listed events rather than every possible account modification.
Key ideas
- Hedging and netting accounts require different rules for interpreting position count and volume changes.
- Pending order count changes help distinguish order placement, removal, and activation.
- Persistent event codes can combine a main event with flags describing how it occurred.
- An EA can expose the most recent event through a query method and display it for inspection.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.