The article shows how to move the GridSurvivor Expert Advisor’s MLP filter from offline training in Python to fully embedded training in MQL5. The network is trained on the history of the current symbol and timeframe, is periodically retrained, and is used as the final signal filter. This approach eliminates external files and normalization mismatches, making the Expert Advisor self-contained and reproducible.
You are developing an MQL5 Expert Advisor and want to add an ML direction filter, but the "train in Python → export weights → load the file" workflow constantly creates technical risks: normalization mismatch, lost weights or the wrong weight version, and discrepancies in feature logic between the offline environment and the terminal. As a result, the filter may behave erratically, and debugging turns into a search for differences between the two code bases.
The purpose of this article is deliberately practical: not to build a "large neural model," but to develop a compact MLP gate that is trained on the history of the current symbol and timeframe, is periodically retrained, and operates only on closed bars. While this filter does not replace a full-fledged research ML pipeline, it solves a specific engineering problem for the Expert Advisor: eliminating external dependencies and integrating training, features, normalization, and inference into a single .mq5 file.
Previously, the project’s MLP was trained offline in Python, and a file containing its weights was exported and loaded into the Expert Advisor. This approach worked, but it regularly caused operational problems: different scalers, different feature versions, forgotten files in MQL5\Files, and difficult troubleshooting when behavior in the tester did not match what was expected from the Python model. Here, we propose a different approach: training a small MLP directly within the Expert Advisor itself using historical data from the same instrument on which it will be applied.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Check out the new article: MLP (Multilayer Perceptron) Inside an MQL5 Expert Advisor: Training on Historical Data Without Python or Weight Files.
You are developing an MQL5 Expert Advisor and want to add an ML direction filter, but the "train in Python → export weights → load the file" workflow constantly creates technical risks: normalization mismatch, lost weights or the wrong weight version, and discrepancies in feature logic between the offline environment and the terminal. As a result, the filter may behave erratically, and debugging turns into a search for differences between the two code bases.
The purpose of this article is deliberately practical: not to build a "large neural model," but to develop a compact MLP gate that is trained on the history of the current symbol and timeframe, is periodically retrained, and operates only on closed bars. While this filter does not replace a full-fledged research ML pipeline, it solves a specific engineering problem for the Expert Advisor: eliminating external dependencies and integrating training, features, normalization, and inference into a single .mq5 file.
Previously, the project’s MLP was trained offline in Python, and a file containing its weights was exported and loaded into the Expert Advisor. This approach worked, but it regularly caused operational problems: different scalers, different feature versions, forgotten files in MQL5\Files, and difficult troubleshooting when behavior in the tester did not match what was expected from the Python model. Here, we propose a different approach: training a small MLP directly within the Expert Advisor itself using historical data from the same instrument on which it will be applied.
Author: Galym Yechshanov