Loading…

Offline Chart Driver

"Programmatically drive an offline chart" gets claimed a lot and delivered rarely, because the honest answer has a hard wall in it: MQL4 file functions are sandboxed to MQL4\Files\ (or MQL5\Files\ on the native MQL5 build) (or Common\Files\ with FILE_COMMON). No FileOpen flag, no relative path, and no documented function reaches the terminal's own history\<server>\ folder, which is where MetaTrader actually reads offline chart data from. Any library claiming to write directly into that folder from inside MQL4 is either lying or relying on something that will break the moment it is checked. This one does not make that claim. What this library does deliver, and does correctly, is the binary format itself. The unified .hst layout used since terminal build ~600 - a 148-byte header (version, symbol, period, digits, timestamps, padding) followed by a run of 60-byte bar records (time, OHLC, tick volume, spread, real volume) - is not officially published by MetaQuotes, but has been independently reverse-engineered and stable for a long time, and is the layout many existing community OHLC-to-HST converters target. This header writes that exact layout using only documented MQL4 file functions (FileWriteInteger/FileWriteLong/FileWriteDouble/FileWriteString), producing a file MetaTrader 4 reads correctly as history once it sits in the right folder. Getting it into that folder is a manual, one-time copy: locate the file in <data folder>\MQL4\Files\ (or MQL5\Files\ on the native MQL5 build), copy it into <data folder>\history\<broker's server folder>\, then use File > Open Offline Chart. The demo script prints these exact steps after writing the file, rather than pretending the file appears as a chart by itself. This is the genuine, working mechanism for programmatic offline-chart data in MQL4 - a correct file plus one manual move - not a shortcut around the sandbox that does not exist. Bar ordering is enforced, not assumed: OfflineChartWriteBar refuses a bar whose time is not strictly after the previous one, and refuses internally inconsistent OHLC (a high below the open/close, a low above them). The terminal's own history reader has no error path for a malformed .hst file - it just displays garbled or empty history - so this library's validation exists to catch the mistake here, where it produces a clear rejection, instead of there, where it produces a broken chart with no explanation. Notes and limitations - MQL4 cannot write outside its own sandbox. This is a genuine platform boundary, not a limitation of this library - moving the finished file into the terminal's history folder is always a manual step (or one done by an external installer/script running outside MQL4 entirely). - The .hst binary layout targeted here (version 401, 148-byte header, 60-byte bar records) is independently reverse-engineered, not an official MetaQuotes specification. It has been stable for a long time and matches what other community tools targeting this format use, but MetaQuotes has never published or guaranteed it, and a future terminal build could change it without notice. - Bars must be supplied strictly ascending in time with no duplicates and internally consistent OHLC. OfflineChartWriteBar refuses anything that breaks these rules rather than writing a file the terminal would then display incorrectly with no error of its own. - This library only writes files. It does not open a chart, does not call ChartApplyTemplate, and does not refresh a symbol's history automatically - all genuinely require either the manual folder move above or a terminal restart/refresh, neither of which an MQL4 script can trigger on itself reliably. - Existing history for the same symbol+period is not merged - writing a file with the same suggested filename overwrites whatever was previously written by this library at that path (though not the real terminal history file, which sandboxing means this library never touches until the manual copy step).

Script · MT4 · v1.0 · Free

About Offline Chart Driver

Offline Chart Driver is a script for MetaTrader 4. It has 2 settings, such as Symbol name and Bar count. MQL source code included.

Files in the download: OfflineChartDriver.mqh, OfflineChartDriver.txt, OfflineChartDriverDemo.mq4.

Settings

SettingDefaultWhat it does
Symbol nameSYNTH1Synthetic symbol name embedded in the .hst header
Bar count20Number of synthetic daily bars to generate

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Renko · Binary Options · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria