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 13): Trend-Scanning Features in Python.
Trend-scanning supports both forward and backward windows, and the labeling default is unsafe for features: it looks ahead and boosts next-bar agreement well above chance on random walks. We provide a dedicated wrapper, get trend scanning features, that forces computational causal and returns only window, slope, t value, and rsquared. A second analysis quantifies errors introduced by the default log transform on signed series.
The MetaTrader 5 Machine Learning Blueprint series introduced trend-scanning as a labeling method: fit OLS regressions over several candidate window lengths, keep the window with the largest absolute t-value, and use its sign as the label. That function, trend_scanning_labels, lives in afml.labeling.trend_scanning and has not changed since. What changes in this article is the question asked of it. A label answers "what happened after this bar." A feature must answer "what was knowable at this bar," and the same function can be made to answer either question, because it exposes both directions through a single argument.
This is a different failure mode than the ones covered so far in this series. Part 11 found a leak baked into a centered rolling window with no causal option available at all, and Part 12 carried the corrected, causal fractal features across to their MQL5 port. Here the causal option already exists: lookforward=False is a first-class, tested code path. The risk is using the labeling-appropriate default when building a feature matrix. Nothing in the function signature prevents the call from succeeding. It returns a well-formed DataFrame that looks correct.
This article wraps trend_scanning_labels in a feature-only interface that removes the choice rather than documenting it. It measures the leak caused by the wrong choice and documents a second, unrelated defect that appears when the function is applied to a signed input series rather than raw price.
Author: Patrick Murimi Njoroge