Skip to content
All library documents

Building a Python MetaTrader Simulator for Historical Bars and Ticks

Article MQL5 articles

Summary

The article extends a Python trading simulator designed to reproduce parts of the MetaTrader 5 interface. It explains how to retrieve historical ticks and bars and describes wrapping many built-in functions for symbol data, orders, positions, account details, and profit or margin calculations. The goal is to let Python strategies use familiar data and query methods in a custom testing environment.

A central engineering problem is the size of tick histories. The author illustrates the memory cost of fetching a long sample at once, then proposes retrieving ticks in monthly chunks, converting them to Polars data frames, and writing partitioned Parquet files. The article also discusses time handling and corresponding simulator methods. These are implementation techniques for data storage and API emulation, rather than a trading strategy. The examples depend on MetaTrader data availability and the simulator's fidelity; the text does not report validation against the terminal's full strategy tester or strategy performance.

Key ideas

  • Historical tick data can consume substantial memory when fetched as one large array.
  • Monthly retrieval and partitioned Parquet storage are presented as a way to manage large tick histories.
  • Polars data frames are used to transform and store tick and bar records.
  • The simulator recreates MetaTrader 5 data and account-query functions for Python strategies.
  • The article focuses on infrastructure and does not establish simulator equivalence or trading performance.

Tags

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