Skip to content
All library documents

Connecting MetaTrader 4 to SQL for Tick and Price-History Data

Article MQL5 articles

Summary

The article describes integrating MetaTrader 4 with Microsoft SQL Server through a DLL and database procedures. Its example stores incoming tick time, symbol, bid, and ask values in a SQL table, with the server assigning its own insertion timestamp. Related procedures can also store historical bars, including timeframe, OHLC values, volume, and bar index. The stored data can then support external analysis, feed signals back to MT4 for execution, or reduce the history retained in the terminal.

The author outlines a legacy setup based on SQL Server 2000, Visual C++, and MDAC, and notes that loading historical bars through a script is slow. Bulk import can be faster, but preserving bar indices across reloads or missing bars presents a data-integrity challenge that the article leaves unresolved. The piece is an integration example, not a measured evaluation of strategy performance; its software versions and implementation details are dated.

Key ideas

  • A DLL and database procedures can transfer MT4 ticks and bar history into SQL Server.
  • The example records symbol, platform timestamp, bid, and ask, while SQL adds a server-side timestamp.
  • External applications can analyze stored quotes and pass signals back to the terminal for execution.
  • Moving history to a database can reduce the amount of data kept in the terminal.
  • Bulk history import may be faster than scripted insertion, but consistent bar indexing remains a challenge.

Tags

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