Discussing the article: "Building a Position Lifecycle Manager in MQL5 (Part 1): The Foundation of Reusable Position Management"

 

Check out the new article: Building a Position Lifecycle Manager in MQL5 (Part 1): The Foundation of Reusable Position Management.

A state-driven Position Lifecycle Manager brings structure to post-entry trade handling in MetaTrader 5. It discovers open positions, tracks them via managed objects, applies ATR-based protection, executes break-even transitions, and removes completed trades, with a clear NEW → PROTECTED → BREAKEVEN → CLOSED flow. The article shows integration with the standard MACD EA to enable reuse across strategies.

Managing a position involves more than tracking an open trade. The framework stores lifecycle data, coordinates decisions, and determines when tracking ends. Traditional Expert Advisors often combine trade generation and position management in the same codebase, making the management logic difficult to reuse across different strategies.

The Position Lifecycle Manager introduces a dedicated management layer that operates independently of the trading strategy. The Expert Advisor remains responsible for generating trades, while the manager automatically discovers newly opened positions, creates their managed representation, and begins tracking their lifecycle.

The framework follows a layered architecture in which each component has a clearly defined responsibility:

  • Expert Advisor – analyses the market and executes trades.
  • Position Manager – coordinates all active managed positions.
  • Managed Position – represents an individual trade and maintains its lifecycle state.
  • Risk Engine – provides supporting calculations required by the management process.

Fig. 1. Position Lifecycle Manager Architecture

Author: Francis Nyoike Thumbi