MetaTrader 5 Python User Group - the summary - page 38

 

Feature Engineering for ML (Part 9): Structural Break Tests in Python

Feature Engineering for ML (Part 9): Structural Break Tests in Python

The preceding articles in this Feature Engineering for ML series built features from the structure of time itself: Part 1 established fractional differentiation as a way to preserve long memory in a stationary series; Part 3 embedded the trading calendar into Fourier coordinates; and Part 5 compressed tick-level order flow into bar-indexed microstructural statistics. This article builds features from a qualitatively different question: not what the current bar looks like, but whether the data-generating process that produced it has recently changed.

Feature Engineering for ML (Part 9): Structural Break Tests in Python
Feature Engineering for ML (Part 9): Structural Break Tests in Python
  • 2026.07.03
  • www.mql5.com
We present a production‑ready implementation of AFML Chapter 17 structural break tests. The module includes Chu-Stinchcombe-White (one-/two-sided), Chow-type DFC, SADF across six models (linear, quadratic, sm poly 1, sm poly 2, sm exp, sm power), plus QADF (q, v) and CADF (q), returning bar-indexed scalar features. We address the book snippets' scaling issues and argument‑order pitfall, and show how a fixed lookback (L=504) bounds SADF cost to O(L²) per bar for regime detection.
 

Feature Engineering for ML (Part 10): Structural Break Tests in MQL5

Feature Engineering for ML (Part 10): Structural Break Tests in MQL5

Part 9 of this series implemented the structural break test suite from AFML Chapter 17 in Python, covering the Chu-Stinchcombe-White CUSUM test, the Chow-Type Dickey-Fuller test, SADF across six regression models, and two robustifying variants (QADF and CADF). This article ports the three core tests — CSW, Chow, and SADF — to MQL5 as a single include file, CStructuralBreaks.mqh, placed in MQL5/Include/StructuralBreaks/. The sub- and super-martingale tests (SM-Exp and SM-Power) are included as well, rounding the suite to five statistics per bar.

The MQL5 implementation departs from the Python version in one structural decision that is worth stating immediately: SADF uses a rolling lookback window rather than a full expanding window. In Python, the expanding window is viable because the computation runs once offline on a fixed dataset. In an EA that recalculates on each new bar, an expanding window scales as O(T²) with the number of completed bars. At T = 1,000 bars — a modest two-year daily series — the expanding window performs 15× more inner-loop operations than a 252-bar rolling window. At T = 5,000 bars it performs 400× more. The rolling window is not a compromise; it changes the interpretation of the statistic slightly, and that change is documented in Section 6.

Feature Engineering for ML (Part 10): Structural Break Tests in MQL5
Feature Engineering for ML (Part 10): Structural Break Tests in MQL5
  • 2026.07.06
  • www.mql5.com
We port AFML Chapter 17 structural break tests to MQL5 as a single include, CStructuralBreaks, delivering six bar-indexed features for EAs: CSW statistic and critical value, Chow-Type DFC, SADF with a rolling lookback (default 252), SM-Exp, and SM-Power. SADF uses O(L²) rolling windows for real-time viability. A companion StructuralBreaksViewer indicator plots all series with per‑series visibility and optional z‑score normalization. SB_EMPTY marks invalid values for safe integration.
 

Feature Engineering for ML (Part 11): Fractal Features in Python

Feature Engineering for ML (Part 11): Fractal Features in Python

The preceding articles in this Feature Engineering for ML series derived features from price geometry (Part 1), from the trading calendar (Part 3), from the bid-ask spread and price impact (Parts 5–6), from the information content of the trade-direction sequence (Part 7), and, most recently, from the timing of regime changes themselves (Part 10). This eleventh installment returns to price geometry, but at a coarser structural level: the swing highs and swing lows that define support, resistance, and trend.

Feature Engineering for ML (Part 11): Fractal Features in Python
Feature Engineering for ML (Part 11): Fractal Features in Python
  • 2026.08.11
  • www.mql5.com
The article examines a Williams five‑bar fractal feature pipeline and shows how a centered rolling window creates a true look‑ahead leak. It identifies two additional silent bugs—a hardcoded shift tied to the default n and a volatility threshold that ignores its input—and consolidates fixes under a single leak_safe flag. Readers get leak‑free fractal, level, trend, and signal features, plus guidance on when unshifted columns remain valid for labeling.