Skip to content
All library documents

Building Python-Compatible Time Features for MQL5 Models

Article MQL5 articles

Summary

The article implements temporal features in MQL5 to match a Python feature pipeline for machine-learning models. It covers Fourier encodings for hour, weekday, and day of year; flags for major forex sessions and their overlap; session-conditioned rolling volatility; and calendar effects. A circular buffer maintains rolling statistics incrementally as closed bars arrive, while initialization, update, and calculation methods produce features in a fixed order for downstream model input.

A central issue is converting broker timestamps to UTC before labeling sessions. The implementation captures the broker-to-UTC offset at initialization, but holds it fixed, so a daylight-saving change during the EA’s run can make session labels inaccurate. The article also aligns weekday and day-of-year indexing with Python and gates higher-frequency hour harmonics by timeframe. It describes a verification script for comparing MQL5 and Python outputs, but supplies no evidence of predictive trading performance; feature compatibility alone does not establish model quality.

Key ideas

  • Broker server time must be adjusted to UTC to label trading sessions consistently with Python features.
  • The captured time offset remains fixed, so daylight-saving transitions can cause session misclassification.
  • Circular buffers support incremental rolling volatility calculations as each closed bar arrives.
  • Weekday and day-of-year indices need conversion to reproduce Python’s cyclical encodings.
  • Feature names, count, and order must remain aligned with the model’s training inputs.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.