Discussing the article: "The MQL5 Standard Library Explorer (Part 17): Building a Reusable Portfolio Manager with CArrayObj"

Check out the new article: The MQL5 Standard Library Explorer (Part 17): Building a Reusable Portfolio Manager with CArrayObj.

We present a multi‑symbol EA structure that moves symbol‑specific state into independently initialized CStrategyNode objects and manages them with CPortfolioManager. Using CArrayObj with FreeMode, Add(), At(), Delete(), Total(), and Clear(), the manager ensures safe ownership and isolation, while timer‑driven routing and completed‑bar gates keep processing deterministic. This lets you scale portfolios, control risk per node, and avoid duplicated event handling.

You already separated classification, decision control and execution inside the EA, but a practical bottleneck remains: the program still treats one symbol at a time. Adding a second instrument quickly multiplies state and checks — separate bar times, magic numbers, failure flags, position checks and event handling — and mixes per-symbol state with MetaTrader 5 event logic. That leads to duplicated code, fragile lifecycle handling (leaks or double deletes), and poor scalability.

This article presents a different approach: encapsulate every symbol-specific state and behavior in an independent CStrategyNode, and let a lightweight CPortfolioManager own and route work to those nodes. CArrayObj (FreeMode(true)) implements a clear ownership contract: allocate an unowned node, Initialize() it, then Add() it (the commit point) so the collection becomes responsible for deletion. A short timer centralizes scheduling while each node keeps its own completed-bar gate and failure state. By the end you will have a practical, testable scaffold for multi-symbol EAs that separates concerns, ensures safe memory ownership, and isolates node failures without duplicating event logic.


Author: Clemence Benjamin