Discussing the article: "MetaTrader 5 Machine Learning Blueprint (Part 13): Implementing Bet Sizing in MQL5"
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Check out the new article: MetaTrader 5 Machine Learning Blueprint (Part 13): Implementing Bet Sizing in MQL5.
We build a production MQL5 bet‑sizing toolkit: utilities, snippets, and user‑level functions that mirror the Python originals. The methods cover probability‑to‑size mapping with overlap correction, dynamic forecast‑price sizing (calibrated sigmoid/power with limit price), occupancy‑based budgeting, and mixture‑model reserve sizing (EF3M). The result is a signed [−1, ..., 1] position plus diagnostics you can plug directly into order logic.
Part 10 of this series derived four bet-sizing methods from first principles and showed their Python implementations in the afml.bet_sizing module. Each method solves a concrete problem: probability-based sizing propagates classifier confidence into position magnitude and corrects for label concurrency; dynamic sizing maps a continuous forecast-price divergence to a position through a calibrated functional form; budget-constrained sizing manages exposure when no confidence score exists; and reserve sizing learns the sizing curve entirely from data. The analytical foundations are now established. What remains is the translation problem: how do you run these methods inside MetaTrader 5, where every computation must fit inside a tick-driven event loop and where there is no SciPy, no NumPy, and no multiprocessing?
This article answers that question in practical terms. It presents four MQL5 include files, one per sizing method, that reproduce the Python module’s mathematical behavior. It also includes a fifth file with the shared data structures and statistical utilities required by all methods. Each file is self-contained enough to drop into an existing Expert Advisor with minimal modification, yet cohesive enough that all four methods can be combined in a single EA that selects the appropriate sizer at runtime. The implementations are exact where exactness is tractable and numerically equivalent where exactness is not tractable. The normal CDF is computed via a minimax rational approximation accurate to seven significant figures.
Author: Patrick Murimi Njoroge