TradingView Import Formatter
TradingView's "Import chart data" feature wants one row per bar with a Unix-seconds (or ISO 8601) timestamp column, strictly ascending, with no duplicate or reordered bar. MetaTrader's own History Center export writes a different shape entirely - a separate DATE and TIME column in broker-local text form, tab-separated - so pasting one export straight into the other tool's import dialog simply does not work. A naive column reshuffle would still ship whatever ordering problem already existed in the source file. This formatter checks explicitly: every consecutive pair of output rows must have a strictly increasing timestamp, and if even one row is out of order or duplicated the whole run is refused with a plain message, rather than handing TradingView a file that will silently render bars in the wrong place on the chart. Column positions are configurable rather than hardcoded to MetaTrader's own export shape, so the same script can reformat a differently-shaped bar CSV from another tool without editing the source. Notes and limitations - The script only reformats. It does not fetch or generate bar data itself - a source CSV must already exist in the sandbox. - A row with an unparsable date/time or a high below the low is skipped and counted, not silently written through. - The run is refused entirely, with no output file written, if the source data is not in strictly ascending, duplicate-free time order. Sort or de-duplicate the source file and run again. - Volume is written as a plain integer tick count. TradingView treats an absent or zero volume column as "no volume data" rather than an error, so InpColVolume can be left at -1 for a source with no volume column at all.
Script · MT4 · v1.0 · Free
About TradingView Import Formatter
TradingView Import Formatter is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 12 settings, such as Input file name, Input is tab delimited and Input has header row. MQL source code included.
Files in the download: TradingViewFormatter.mq4, TradingViewFormatter.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Input file name | history_export.csv | Input file, from MQL4\Files |
| Input is tab delimited | true | true = tab (MT4 History Center export), false = comma |
| Input has header row | false | Skip the first row of the input file |
| Col date | 0 | Column index (0-based) holding the date, e.g. 2024.01.02 |
| Col time | 1 | Column index holding the time, e.g. 00:00 (-1 = date column already includes time) |
| Col open | 2 | Column index holding Open |
| Col high | 3 | Column index holding High |
| Col low | 4 | Column index holding Low |
| Col close | 5 | Column index holding Close |
| Col volume | 6 | Column index holding Volume (-1 = no volume column, output 0) |
| Time output | TimeOutputUnix | Timestamp format written to the output file |
| Output file name | tradingview_import.csv | Output file, written to MQL4\Files |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 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 · MT4 Script · MQL4 Source Code