CSV To Offline Chart Data
Getting bar data that did not come from your broker onto a chart - a competitor's export, a synthetic series, data recovered from an old platform - is something the terminal gives you no direct way to do. This script is the missing step. Feed it a CSV with the columns time, open, high, low, close, volume (the exact layout Export OHLC To CSV produces), and it produces either a .hst history file (MQL4) or a live custom symbol (MQL5) that MetaTrader can chart like any other instrument. The trap this script is built to avoid is a silently mislabelled file. A .hst or a custom symbol carries its own timeframe in its data - if that timeframe does not match the actual spacing of the bars inside it, the chart does not error, it just misdraws every bar, and the mistake is invisible until someone notices the highs and lows look wrong. Before writing anything, this script measures the actual gap between bars (the median gap across the first 100 rows, so one weekend or holiday inside the sample cannot skew it) and refuses outright if that does not match the timeframe you selected. Bars that arrive out of order or with a duplicate timestamp are refused for the same reason - a corrupted offline series looks fine until it does not. The .hst side of MQL4 is written to the documented format 401 layout used since build 600: a 148-byte header (version, copyright, symbol, period, digits, timesign, last_sync, thirteen reserved integers) followed by 60-byte bar records in the same field order as the MqlRates structure - time, open, high, low, close, tick volume, spread, real volume. Spread and real volume are not in the source CSV and are written as zero, which the terminal treats as unknown rather than as a claim about the actual spread. Notes and limitations - Quoted fields are out of scope - a comma inside a quoted value in the CSV will misparse. Export OHLC To CSV's own output never quotes a numeric column, so this is only a concern with a hand-edited or third-party file. - The .hst format used is the current "format 401" layout (build 600 onward). Very old MetaTrader 4 builds used a different, smaller bar record and will not read this file. - The median-spacing check samples the first 100 bars. A file whose spacing changes partway through (two different sources concatenated, for instance) will not be caught if the first 100 rows happen to be regular. - MQL4's symbol field is 12 bytes including a terminating zero; a symbol name over 11 characters is truncated in the header, though the filename itself is not. - This script has been checked for a clean compile against the documented format. Confirm the actual offline chart opens correctly with real data before relying on it - a header field this script cannot see MetaTrader reject (a future format revision, for instance) would show up there first.
Script · MT5 · v1.0 · Free
About CSV To Offline Chart Data
CSV To Offline Chart Data is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 7 settings, such as Csv file name, Delimiter and Csv has header row. MQL source code included.
Files in the download: CsvToHstHelper.mq5, CsvToHstHelper.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Csv file name | bars.csv | CSV file to convert, in MQL5\Files |
| Delimiter | DelimiterComma | Column separator used in the CSV |
| Csv has header row | true | First CSV line is a header - skip it |
| Source symbol | Symbol to copy properties from (blank = this chart's symbol) | |
| Custom symbol suffix | .import | Appended to the source symbol to name the custom symbol |
| Period | PERIOD_H1 | Timeframe the CSV's bar spacing must match, and the chart opened at the end |
| Replace existing | false | Replace rates if the custom symbol already exists (default: refuse) |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Volume · Alerts · MT5 Script · MQL5 Source Code