Discussing the article: "Building Your Personal Expert Advisor (Part 6): Risk Management V — Portfolio and Correlated Risk"

 

Check out the new article: Building Your Personal Expert Advisor (Part 6): Risk Management V — Portfolio and Correlated Risk.

This part implements PortfolioRisk.mqh, a shared library that shifts risk management to the account level. It scans positions and pending orders, computes margin and floating results, counts symbols, and decomposes pairs into currencies to detect concentration, then validates each new trade against portfolio limits. The Series EA example illustrates configuring scope (account-wide or magic-filtered), registering magics, and integrating the pre-trade gate.

The previous part taught the EA to see its own basket. Our EA can now measure its own basket. It treats every position it holds on its symbol as one unit, caps what that unit may lose, caps the margin it ties up, and reports how far against it things went at their worst. It still sees nothing else. Run the same EA on three charts, and each copy believes it is the only thing in the account.

The broker has no such illusion. Margin, margin level, and a margin call are account-wide facts. An account can be emptied by the sum of positions that were each individually well managed. This article builds a library that measures the account rather than the strategy and an EA that consults it before every trade.

Author: Solomon Anietie Sunday