Skip to content
All library documents

Porting Kronos Candlestick Tokenization and Transformer Operations to MQL5

Article MQL5 articles

Summary

This article’s first installment explains how to bring parts of the Kronos candlestick foundation model into native MQL5. It covers offline export of PyTorch parameters to binary float files, candle preprocessing, and the tokenizer encoder, which compresses six bar features into hierarchical discrete tokens using Binary Spherical Quantization. It also describes transformer components such as RMS normalization, rotary position embeddings, gated feed-forward layers, and causal attention.

The focus is implementation fidelity rather than forecasting results. The author explains why native code is used for the full pipeline, including autoregressive control flow and changing key/value caches that remain outside a simple static graph. A verification ladder compares MQL5 operations and encoded tokens with fixed PyTorch reference outputs, with exact integer token agreement presented as the correctness check. The predictor, decoding, forecast generation, and assessment of predictive value are deferred to later parts, so this installment does not show that the model produces useful trading forecasts.

Key ideas

  • Kronos represents candlestick sequences as discrete tokens and uses a transformer to model token histories.
  • The tokenizer encodes six candle features into coarse and fine binary-quantized subtokens.
  • The MQL5 port uses offline float-weight exports and native matrix operations at runtime.
  • A reference harness checks the port against PyTorch outputs, including exact token indices.
  • This installment addresses preprocessing and encoding, not forecast performance or trading profitability.

Tags

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