Skip to content
All library documents

Account-Wide Portfolio Risk and Currency Exposure Controls in MQL5

Article MQL5 articles

Summary

This article describes a reusable MQL5 library for measuring portfolio-wide exposure and checking it before an EA opens a trade. It distinguishes account-wide monitoring from a magic-number filter, then outlines a snapshot of positions, pending orders, symbols, volume, floating profit and loss, and margin. Currency exposure is estimated by decomposing each forex position into signed base- and quote-currency lots, with net and gross amounts providing complementary views of concentration.

The EA consults limits for total positions, positions per symbol, number of symbols, margin use, account loss, and net currency lots during trade validation. The article explains why shared measurement belongs in a common library: a private limit can be bypassed by another EA. It also notes important limits: filtered margin is approximate, Pearson correlation is not implemented, measurements do not persist through terminal restarts, and simultaneous EA checks can both pass before either opens a trade. The examples explain the design, but no test results are reported.

Key ideas

  • Portfolio risk limits are meaningful only when participating EAs measure the same account view.
  • Account-wide scope includes all positions and uses the terminal's exact account margin figure.
  • Currency-level net and gross lots can reveal shared directional exposure across different forex pairs.
  • The library checks position, symbol, margin, loss, and currency limits before trade entry.
  • Filtered margin is approximate, and separate EAs do not coordinate simultaneous trade decisions.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.