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.
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.
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.
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.
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.
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.
MetaTrader 5 can load a trained neural network and run it. Pass the model file path to the ONNX (Open Neural Network Exchange) API, feed a tensor, and receive predictions. The terminal does not reveal what the ONNX file contains: the layer count, required input shape, or which weights were saved. When outputs look wrong, you cannot quickly tell whether the issue is in the features, tensor shapes, or the file itself, because the model is treated as an opaque binary. This article targets MetaQuotes Language 5 (MQL5) developers and algorithmic traders who train models elsewhere and want to inspect them inside the terminal, without leaving MetaTrader 5 and without a single external library.
When you are developing trading robots for MetaTrader 5 in Python and face a familiar split: for live trading you call the MetaTrader5 package, while for backtesting you must build and maintain a separate tester layer with different initialization, data sources and APIs. The result is duplicated logic, brittle synchronization between two code paths, and wasted time every time you change your strategy. What we want instead is an MQL5-like workflow in Python: a single EA-style main() (OnTick) implementing trading logic once, and the ability to run that same code against historical data or in the live market without rewriting it.
This article shows how the StrategyTester5 framework achieves that: it provides a VirtualMetaTrader5 that mirrors the MetaTrader5 API, a simple mt5 variable swap to switch environments, and a run_backtesting() function that replays market data and returns a TesterStats object. The goal is practical: write your strategy once, then choose whether to run it on history or on a live account.
To make sure I understand correctly, does your statement also apply specifically to history_orders_get() and history_deals_get() , including date_from , date_to , ORDER_TIME_SETUP , ORDER_TIME_DONE , DEAL_TIME and the corresponding *_MSC fields?
Also, do you know whether date_to is inclusive or exclusive, and at what precision?
Finally, since you reported the datetime/timezone documentation issue to MetaQuotes, is there any official MetaQuotes ticket, updated documentation page, or confirmation that can be cited?
Thank you.
The same applies to the whole API.
You need to use UTC timezone in your parameters, and the returned data are broker server time.
We built a reader that opens an ONNX file and tells us what is inside it. It works, and the report is accurate, but it arrives as a wall of text in the Experts tab. Thirteen layers scroll past with their input and output names. To understand the connections, we must trace those names by eye, line by line, while keeping the graph's structure in mind. A model with two parallel branches reads exactly like a model with one long chain, because a list has no way to show that two layers run side by side. The thing we most want to know about a network, its shape, is the one thing a list cannot give us. This article is for MetaQuotes Language 5 (MQL5) developers and algorithmic traders who want to see the model they are running rather than read about it.
MetaQuotes Language 5 (MQL5) is a specialized C++ based high-level object-oriented programming language. All trading applications for MetaTrader 5 are written in MQL5. The major difference of MQL5 from other programming languages is its trading...
In the previous part, we put the model on the chart and could finally see its shape. The layers sit in the right order, the branches read as branches, and clicking a weight tells us its range and its spread. What none of it shows is the network. A box marked "Gemm" with a row reading twenty-four by sixteen tells us a matrix is in there, and stops. The matrix holds which input reaches which neuron, whether each connection pushes or pulls, and which inputs dominate. None of that is drawn. We see the architecture, but the weights remain just numbers in a panel. This article is for MetaQuotes Language 5 (MQL5) developers and algorithmic traders who want to look inside a trained model rather than at its outline.
We build a neuron-level view for MQL5 models: count neurons per row, compute ranks, and render one line per stored weight from dense layers. The implementation reads matrix orientation from attributes, colors connections by sign and relative strength, and keeps activations on the same row. You can toggle between the layer graph and neurons, or see why the neuron view is unavailable, to analyze how weights connect inputs to outputs.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
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 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 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.
Working with ONNX Models in MQL5 (Part 1): Decoding the Model File with a Protobuf Parser
MetaTrader 5 can load a trained neural network and run it. Pass the model file path to the ONNX (Open Neural Network Exchange) API, feed a tensor, and receive predictions. The terminal does not reveal what the ONNX file contains: the layer count, required input shape, or which weights were saved. When outputs look wrong, you cannot quickly tell whether the issue is in the features, tensor shapes, or the file itself, because the model is treated as an opaque binary. This article targets MetaQuotes Language 5 (MQL5) developers and algorithmic traders who train models elsewhere and want to inspect them inside the terminal, without leaving MetaTrader 5 and without a single external library.
Python-MetaTrader 5 Strategy Tester (Part 06): MQL5-Style Backtesting for Python Expert Advisors
When you are developing trading robots for MetaTrader 5 in Python and face a familiar split: for live trading you call the MetaTrader5 package, while for backtesting you must build and maintain a separate tester layer with different initialization, data sources and APIs. The result is duplicated logic, brittle synchronization between two code paths, and wasted time every time you change your strategy. What we want instead is an MQL5-like workflow in Python: a single EA-style main() (OnTick) implementing trading logic once, and the ability to run that same code against historical data or in the live market without rewriting it.
This article shows how the StrategyTester5 framework achieves that: it provides a VirtualMetaTrader5 that mirrors the MetaTrader5 API, a simple mt5 variable swap to switch environments, and a run_backtesting() function that replays market data and returns a TesterStats object. The goal is practical: write your strategy once, then choose whether to run it on history or on a live account.
Forum on trading, automated trading systems and testing trading strategies
MetaTrader5 Python history_orders_get/history_deals_get — authoritative time semantics
Alain Verleyen, 2026.09.25 15:05
Forum on trading, automated trading systems and testing trading strategies
MetaTrader5 Python history_orders_get/history_deals_get — authoritative time semantics
Savane Oumar, 2026.09.25 13:10
Thank you, this is very important.
To make sure I understand correctly, does your statement also apply specifically to history_orders_get() and history_deals_get() , including date_from , date_to , ORDER_TIME_SETUP , ORDER_TIME_DONE , DEAL_TIME and the corresponding *_MSC fields?
Also, do you know whether date_to is inclusive or exclusive, and at what precision?
Finally, since you reported the datetime/timezone documentation issue to MetaQuotes, is there any official MetaQuotes ticket, updated documentation page, or confirmation that can be cited?
Thank you.
The same applies to the whole API.
You need to use UTC timezone in your parameters, and the returned data are broker server time.
Working with ONNX Models in MQL5 (Part 2): Drawing the Model Graph on an Interactive Chart Panel
Working with ONNX Models in MQL5 (Part 3): Drawing the Neurons and the Weights Between Them