Discussing the article: "Building a Position Lifecycle Manager in MQL5 (Part 2): Managing Manual and Multi-Symbol Positions"

Check out the new article: Building a Position Lifecycle Manager in MQL5 (Part 2): Managing Manual and Multi-Symbol Positions.

This update adds manual position adoption and multi-symbol lifecycle management. The manager detects and tracks positions regardless of the chart, applies initial protection, transitions to break-even under fixed or ATR triggers, and validates broker constraints per symbol. Using the MACD sample for context, it demonstrates reusable management across instruments and manually opened trades.

In Part 1, we built the foundation of the Position Lifecycle Manager around a clear separation of responsibilities. The MACD sample EA generated trading signals and opened positions, while the Position Manager handled protection and subsequent lifecycle management. Part 2 extends this architecture by moving order submission into the Position Manager.

This included protection, break-even management, lifecycle state and continuous monitoring. This phase focuses on extending that foundation to manual and multi-symbol position management.

While the MACD example continues to provide the trading context, broader testing exposed an important limitation. The manager was still using the chart symbol as part of its position discovery and management context. That works for a conventional single-symbol EA but limits the reusability of the component.

A position manager should follow the position it manages rather than the chart where the manager happens to be attached.

This becomes particularly important in Manual Mode. The manager can remain attached to one chart while a trader opens positions on other instruments. Those positions should be detected, adopted and managed without requiring another manager instance on each chart.

The same principle applies to EA Mode. Once a position has been identified as belonging to the configured trading system, its own symbol should determine the market data, price calculations, broker constraints and execution settings used throughout its lifecycle.

The resulting architecture can be summarized in the  following diagram.

Fig. 1. Position manager flow


Author: Francis Nyoike Thumbi

When a trader is trading multiple instruments, it is best to calculate the break-even point for each instrument separately, taking into account the spread and commission. Otherwise, a stop-loss set at the opening price will close the trade at a loss. Example: EURUSD, with a commission of $7 per lot round trip (equivalent to 0.7 pips), plus a spread of 0.2. The stop-loss must be set at least 1 pip beyond the entry point; otherwise, every ‘break-even’ trade will result in a loss of $9 per lot. For gold and indices, this margin is different, so it is convenient to derive it from `SYMBOL_SPREAD` and the trade history, rather than specifying a single value in the input parameters. And before making any modifications, it is worth checking SYMBOL_TRADE_STOPS_LEVEL and SYMBOL_TRADE_FREEZE_LEVEL specifically for the symbol of the position; with manual positions on third-party charts, error 130 is triggered precisely because of this.

Nikita.PMC #:

When a trader is trading multiple instruments, it is best to calculate the break-even point for each instrument separately, taking into account the spread and commission. Otherwise, a stop-loss set at the opening price will close the trade at a loss. Example: EURUSD, with a commission of $7 per lot round trip (equivalent to 0.7 pips), plus a spread of 0.2. The stop-loss must be set at least 1 pip beyond the entry point; otherwise, every ‘break-even’ trade will result in a loss of $9 per lot. For gold and indices, this margin is different, so it is convenient to derive it from `SYMBOL_SPREAD` and the trade history, rather than specifying a single value in the input parameters. And before making any modifications, it is worth checking SYMBOL_TRADE_STOPS_LEVEL and SYMBOL_TRADE_FREEZE_LEVEL specifically for the symbol of the position; with manual positions on third-party charts, error 130 is triggered precisely because of this.

Thanks for highlighting this. The current implementation uses price based break-even calculations and does not yet provide comprehensive instrument specific cost accounting at the campaign level. We plan to address this in a subsequent development stage by introducing a dedicated cost accounting layer covering commissions, swaps and fees, alongside instrument specific break-even calculations that account for execution costs and symbol trading constraints.