Skip to content
All library documents

Preventing Timestamp Leakage with Tick-Based Market Bars

Article MQL5 articles

Summary

This article explains how bar timestamps can create look-ahead bias in financial machine-learning datasets. MetaTrader 5 time bars are labeled with their opening time, although their high, low, close, and other completed-bar features are only known later. Even end-of-bar timestamps can leak information if a model is assumed to act at the start of that same interval. The article recommends aligning features and predictions with the moment their information becomes available and constructing bars from tick data.

It compares time bars with activity-based sampling, especially tick bars, and describes Python procedures for retrieving and cleaning ticks and building bars. For EURUSD data from 2023–2024, it reports that tick-bar returns were closer to normal than time-bar returns across the compared intervals, while neither distribution was normal. It also reports that time bars concentrated more total price change in their most active portion. These observations are sample-specific; forex volume data is unavailable in the described setting, and the article limits its bar discussion to time and tick bars. Its statistical comparisons do not establish that tick bars improve trading performance.

Key ideas

  • MetaTrader 5 time bars use opening timestamps even though completed-bar features become known later.
  • A model must use only features available at the time its prediction or trading decision is made.
  • Tick bars complete after a specified amount of tick activity and can align features with information availability.
  • The article reports more regular return distributions for tick bars in its EURUSD sample, but not normality or proven trading gains.
  • The described workflow retrieves and cleans tick data before constructing time or tick bars.

Tags

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