Discussing the article: "The MQL5 Standard Library Explorer (Part 13): Implementing the Math Solvers Library in Trading"
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: The MQL5 Standard Library Explorer (Part 13): Implementing the Math Solvers Library in Trading.
We present a complete workflow for adaptive filtering in MQL5 using the CNlEq Levenberg–Marquardt–like solver. The EA fits a VAMAC model—two EWMAs with an ATR‑based scaling—by supplying residuals and a Jacobian through CNlEq's reverse‑communication loop, with optional numerical or analytical derivatives. Code, setup instructions, and GBPUSD H1 tests show how to replace static thresholds with on‑bar re‑estimation.
We introduce a custom Expert Advisor that uses the Levenberg‑Marquardt nonlinear solver – provided by the MQL5 Standard Library through the CNlEq class – to dynamically fit a volatility‑adjusted signal filter, automating parameter tuning on a rolling window of historical data.
The core innovation of this system is the use of the CNlEq solver (initialized via NlEqCreateLM) to perform online parameter estimation on a nonlinear volatility‑adjusted filter. Instead of relying on fixed indicators or manual optimization, the Expert Advisor repeatedly solves a least‑squares problem over a sliding window of price data. The result is a signal filter whose coefficients adapt to changing market regimes without human intervention.
Why Levenberg‑Marquardt?
solvers.mqh is a port of ALGLIB and includes multiple solvers: CLSQR, CCG, and CNlEq (Levenberg–Marquardt). For this problem, we need to fit up to four parameters (filter coefficients and a volatility scaling factor) with a nonlinear objective function. The LM algorithm excels here because it combines the speed of Gauss‑Newton near the optimum with the stability of gradient descent far from it. In practice, this hybrid behavior yields robust convergence even when the initial parameter guesses are poor – a critical requirement when the market environment shifts abruptly.
Author: Clemence Benjamin