The article " Using L1 Trend Filtering in MetaTrader 5" has been published:
Author: MetaQuotes
This is excellent, well done MetaQuotes.Prof. Stephen Boyd from Stanford University and his legendary time series findings in mql5.
This is excellent, well done MetaQuotes.Prof. Stephen Boyd from Stanford University and his legendary time series findings in mql5.
Thank you. The method has no boundary problems, so that's why its applications may be useful in trading.
After the article was ready, it has been found that the best way is add volume on trend corrections, (this moment is not considered in the article), see the Expert Advisors here: MA, MACD, ADX, EMA.
The Expert Advisors with adding on trend corrections:
- 2026.04.10
- www.mql5.com
The script shows L1 trend filtering for the different lambda (defined in λmax units as lambda_factors = {1.0,0.8,0.5,0.2,0.1,0.01,0.001});
See other examples in https://forge.mql5.io/quantum/L1Trend
- quantum
- forge.mql5.io
Splitting into trends depends very much on the regularisation parameter lambda - the smaller the lambda, the shorter trends it is able to catch.
In the considered examples, fixed values of lambda in units lambda=0.2*lambda_max were used. Calculation in units of lambda_max partly allows to adapt to the data. The lambda_max value itself depends on the geometry of the series (relative spreads), i.e. volatility.
It should be kept in mind that a trend has different phases and its own life cycle. Therefore, we need some mechanism for adjusting to the current trend, i.e. somehow manage lambda and find the optimal trend split - this task has not been solved yet.
If the strategy itself does not give profit on the interval, the filter will not help either.
The best results should be on an ideal trend market, the example was as follows: EURUSD, 2025, H1 (the best parameters MovingAverage period=61).



L1 Close filter

Here we can see that the exit filter helped to increase the profit on the trend area.
A variant of the same strategy with adding positions on corrections:

Without additions:
With additions:

Intervals with flat market contain local small trends and in order to take them into account correctly, we should use smaller values of the lambda parameter (when used as an exit filter).
Besides, the best values of MovingAverage parameters on the flat market interval should be different. I.e. the optimal periods of averages on the second interval have changed (but when optimising in the tester the found parameters give the highest profit among all others on the whole interval of optimisation).
Let's check the results on flat interval with different lambda.

Without filters:

With output filter lambda=0.2*lambda_max

With filter lambda=0.001 lambda_max (smaller trends).

Thus, on the flat section at lambda=0.001 lambda_max we can improve the result without filters and take into account local small trends.
However, the variant with the filter lambda=0.2*lambda_max here showed lower profitability than the strategy without filters.
Variant with adding positions (different lambda) on local trends within flatness

Without filters:

C filter lambda=0.2*lambda_max and adding on corrections:

C filter with lambda=0.001*lambda_max and addition on corrections:

The variant with filter with lambda=0.2*lambda_max and addition on corrections showed better result than the variant without filters.
Adding local small trends (lambda=0.001*lambda_max) inside the flat interval on corrections allowed increasing the profit of the original strategy without filters (and improving the variant with lambda=0.2*lambda_max in terms of profit).
Variant with adding positions (different lambda) on local trends within flatness
Without filters:
C filter lambda=0.2*lambda_max and adding on corrections:
C filter lambda=0.001*lambda_max and addition on corrections:
The variant with filter with lambda=0.2*lambda_max and addition on corrections showed better result than the variant without filters.
Adding local small trends (lambda=0.001*lambda_max) inside the flat interval on corrections allowed increasing the profit of the original strategy without filters (and improving the variant with lambda=0.2*lambda_max in terms of profit).
trade, at least on demo
understanding will come with experience and after waiting 10 months of useless work.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use











Check out the new article: Applying L1 Trend Filtering in MetaTrader 5.
This article explores the practical application of L1 trend filtering in MetaTrader 5, covering both its mathematical foundations and usage in MQL5 programs. The L1 filter enables extraction of piecewise-linear trends that preserve essential market structure while reducing price noise. The study analyzes parameter scaling, trend estimation behavior, and integration of the method into algorithmic trading strategies. Experimental results demonstrate how L1 trend filtering can enhance signal stability, trade timing, and overall robustness of trading systems.
Financial time series are characterized by high noise levels, frequent outliers, and changing market regimes. In practical trading systems, this manifests in a simple and measurable way: classical “smooth” filters (moving averages, HP) lag behind, blur the moments of slope changes, and often interpret local corrections as reversals — as a result, the number of false entries/exits increases, the Profit Factor decreases, and drawdown grows. In addition, the selection of the regularization parameter λ is usually reduced to manual tuning and does not transfer well across instruments, timeframes, and history lengths.
This paper proposes a practical solution to these problems based on L1 trend filtering: optimization with L1 regularization of second differences automatically produces a piecewise-linear approximation with explicit breakpoints. The key advantages are a clear interpretation of breakpoints as regime changes, the ability to set the scale of regularization via computing λmax and moving to a relative parameter λ = coef · λmax, as well as linear computational complexity suitable for implementation in MQL5.
We present not only the theory, but also a complete practical roadmap: methods for computing λmax and the L1 trend, three indicators (trend, slope, slope sign), seven L1-trend volatility indicators, integration into Expert Advisors, and a reproducible testing protocol (four filtering modes, balance/equity export, and visualization).
Author: MetaQuotes