Skip to content
All library documents

Querying SQLite from MQL5 and Handling Built-In Database Differences

Article MQL5 articles

Summary

This installment in a market replay and simulation series shows how to extend an MQL5 class so it can execute queries against SQLite and retrieve results. It explains the workflow of embedding SQL scripts, creating related symbol and quote tables, inserting sample market data, and adapting the application to run the scripts. The focus is database access for simulation infrastructure rather than a trading signal or strategy.

A central caution concerns behavior observed in the MetaTrader 5 built-in SQLite implementation: rerunning a script that drops tables with populated foreign-key relationships may fail, even though the same script reportedly runs in standalone SQLite. The author notes the tested terminal build and recognizes that behavior may change; the precise cause is uncertain. Deleting the database file is offered as a workaround for resetting the tables. The article advocates checking the behavior of the specific embedded database implementation and testing queries directly. It also mentions ONNX as an alternative more suited to machine-learning models, while SQL can still support modeling tasks.

Key ideas

  • The article extends an MQL5 database wrapper to execute SQLite queries and retrieve results.
  • The example schema links quote records to symbols with a foreign key.
  • The author reports that dropping populated related tables behaved differently in a tested MetaTrader 5 build than in standalone SQLite.
  • Deleting the database file is presented as a practical reset workaround for that observed issue.
  • Embedded SQLite behavior can change between platform versions, so implementation details should be tested in the target environment.

Tags

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