Activity and Imbalance Bars for Market Tick Data
Summary
This article explains why fixed-time bars can assign equal weight to periods with very different trading activity, then presents activity-based alternatives inspired by AFML. It covers time, tick, volume, and dollar bars, plus imbalance bars that close when directional activity crosses an adaptive threshold. A unified Python interface handles batch construction, while an MQL5 implementation supports live tick-by-tick use. The article also describes Parquet partitioning and Dask for loading large histories, and a cleaning pipeline for invalid spreads, duplicate timestamps, missing times, and unsorted ticks.
Implementation details include automatic threshold calibration, EWM state persistence across EA restarts, and a parity check comparing output from the Python and MQL5 versions on the same tick stream. These are engineering demonstrations rather than evidence that any bar type improves strategy returns. The article notes implementation differences between the two versions and depends on clean input data and appropriate threshold calibration; sampling choices still require validation for the intended market and application.
Key ideas
- Clock-time bars can contain widely varying amounts of market activity, which may distort downstream features.
- Tick, volume, dollar, and imbalance bars define observations using activity or directional flow.
- Cleaning tick data and removing empty time bars helps prevent invalid observations from entering feature pipelines.
- The article pairs batch Python processing with live MQL5 construction and describes state persistence for adaptive thresholds.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.