Building Custom Risk and Money Management Modules in MQL5
Summary
This article explains how MQL5 Expert Advisors use the CExpertMoney base class to handle position sizing and other money-management decisions. It describes the roles of its initialization, parameter validation, indicator setup, entry-volume, reversal, and closing methods, and explains when a custom module should override them. The EA consults the module for proposed volumes or closure decisions and remains responsible for acting on those proposals.
The implementation walkthrough covers deriving a class, placing it where the MQL5 Wizard can discover it, and exposing its parameters for use in generated EAs. The example uses a rule that adjusts trade volume based on the previous deal, with a doubling-after-loss approach, and reports a historical test setup for EURUSD on H1. That example is illustrative rather than evidence of robust profitability: the article gives no broader validation, and its guidance is specific to the MQL5 Standard Library and Wizard workflow. It also recommends using the Strategy Tester to explore parameter values.
Key ideas
- CExpertMoney provides hooks for initialization, validation, and money-management decisions in an Expert Advisor.
- Override entry-volume methods when custom long or short sizing differs from the base implementation.
- Custom modules can also define reversal volume and whether or how much of a position to close.
- MQL5 Wizard discovery depends on the module's location and its parameter description.
- The article illustrates volume doubling after a loss, but its single historical test setup does not establish general performance.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.