Great write up!
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: Feature Engineering for ML (Part 14): Trend-Scanning Features in MQL5.
A naive MQL5 port of trend-scanning features recomputes each candidate window per bar at O(H·L) cost. This article introduces CTrendScanningFeatures.mqh, which maintains three running sums per horizon and updates them in O(1) per bar, verified against a Python reference. The indicator exposes four causal buffers - window, slope, t_value, rsquared - at the confirmation bar and corrects a sign inversion present in the original backward labeling mode.
Part 13 wrapped afml.labeling.trend_scanning in a causal-only feature interface, get_trend_scanning_features, that removes the lookforward argument rather than documenting it, because the labeling default is unsafe to call from a feature matrix. This article ports the same causal computation to MQL5 as CTrendScanningFeatures.mqh. Implementing it from first principles instead of relying on the reversal trick used in Python exposed a defect inherited by the Python code: trend_scanning_labels(lookforward=False) returns slope and t-value with the wrong sign.
Section 4 and Section 5 document the finding and its impact on the shipped Part 13 wrapper, with supporting evidence. Section 9 covers a second and separate finding, which concerns the method rather than the code: the rule for choosing among candidate windows does not select the most significant trend, and the t-value it reports cannot be read against the nominal Student-t threshold on price data. Both claims are established by simulation rather than argument.
The rest of the article covers the engineering the port required on its own terms: an O(1)-per-horizon incremental update in place of Part 13's full-window recomputation, a volatility-masking simplification that falls out of the module's own default parameter, and a chart indicator exposing four causal feature buffers through the same iCustom contract used throughout this series.
Author: Patrick Murimi Njoroge