Skip to content
All library documents

Entropy Features for Measuring Trade-Direction Information in Market Data

Article MQL5 articles

Summary

The article explains four ways to measure information in the sequence of trade directions within a bar: Shannon entropy for symbol frequencies, plug-in entropy for repeated blocks, Lempel-Ziv complexity for compressibility, and Kontoyiannis entropy for average match lengths. These features distinguish directional imbalance from sequential patterns; for example, two sequences can have the same buy-sell counts but different ordering. The inputs are encoded tick-rule symbols, and the article also describes encoding numeric data into bins.

A major focus is implementation: it identifies a Numba string-handling fallback that slowed Kontoyiannis calculations, a phrase-library membership error in Lempel-Ziv, and a truncation detail affecting plug-in results. It describes converting inputs to byte arrays, vectorizing block counts, and using compiled integer-based kernels. Reported timing improvements and test results are evidence about this implementation, not evidence that entropy signals predict returns. The features summarize order-flow structure, and their usefulness for trading still requires validation in a defined forecasting or trading task.

Key ideas

  • Shannon entropy measures the balance of trade-direction symbols, while block and sequence estimators capture ordering and repetition.
  • Lempel-Ziv complexity is lower for repetitive, compressible messages and higher for less predictable sequences.
  • Kontoyiannis entropy estimates predictability through the lengths of matches in prior history.
  • Converting messages to byte arrays avoids Python string operations in compiled kernels.
  • Implementation speedups and numerical tests do not establish predictive or trading value.

Tags

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