Designing a Reusable MQL5 Position Lifecycle Manager
Summary
This article introduces a reusable framework for managing positions after an Expert Advisor opens them. It separates trade generation from ongoing position management and organizes the work among a coordinator, an object for each managed position, and a supporting risk-calculation component. Each position object stores identifying and initial trade information alongside runtime state, while the manager discovers new positions, processes active ones, and removes closed positions from tracking.
The first installment establishes a lifecycle model with stages for newly registered, protected, breakeven, and closed positions. It demonstrates the architecture by integrating the manager with the MQL5 Standard Library MACD Expert Advisor while leaving its trading logic unchanged. The article provides design explanations and implementation components, rather than comparative performance results. This is a foundation for later management features; the framework's value depends on the rules added to it, and the article does not show that its example improves the MACD strategy's returns.
Key ideas
- The manager separates position handling from the strategy that generates trades.
- A coordinator tracks multiple positions while an individual managed object stores each position's data and state.
- Lifecycle states record which stages and management actions a position has reached.
- The manager discovers open positions, updates their representations, and cleans up after closure.
- The example integrates the framework with an unchanged MACD Expert Advisor and does not report performance results.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.