Offline Tick To Bar Rebuilder
MetaTrader's built-in timeframes are a fixed list. There is no way to view or export true 7-minute or 90-second bars from the terminal itself - the closest available period must be approximated by compressing M1, which is not the same thing as bars actually built from tick-level price movement at that period. This script builds real bars of any custom minute length directly from a recorded tick CSV, with no dependency on the terminal's own bar history at all. Bar boundaries are floored to fixed multiples of the requested period counted from the Unix epoch - a broker-independent, honest convention for an offline rebuild that has no session calendar available to align to instead. This is stated plainly rather than implying the output matches what the terminal's own custom-period charts would show, which align to session opens, not epoch multiples. A quiet period - a weekend, a data gap, a session with no recorded ticks - produces no bar at all for that stretch, rather than a fabricated flat bar carried forward from the last known price. The input tick file must already be sorted ascending by time; the script checks this explicitly and refuses the whole file rather than silently building bars from a corrupted bucket assignment if it finds a timestamp that goes backwards. Notes and limitations - Bars use the bid price only, the standard convention most historical tick feeds already follow, since a tick file rarely carries a reliable matching ask for every row. - Bucket boundaries align to fixed multiples of the period since the Unix epoch, not to a broker's session open. A 7-minute bar built this way will not line up exactly with a hypothetical broker-native 7-minute chart that aligns to session start instead. - The tick file must already be sorted ascending by time. The script detects and refuses an out-of-order file rather than attempting a partial or best-effort rebuild. - Volume in the output is a tick count for that bucket, not a real traded volume figure - forex has no genuine trade volume on either MetaTrader platform. - This is a one-shot offline conversion. It does not watch a growing tick file or update bars incrementally; run it again on the full, updated tick file to regenerate.
Script · MT4 · v1.0 · Free
About Offline Tick To Bar Rebuilder
Offline Tick To Bar Rebuilder is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 7 settings, such as Input file name, Input is tab delimited and Input has header row. MQL source code included.
Files in the download: OfflineTickBarRebuilder.mq4, OfflineTickBarRebuilder.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Input file name | ticks.csv | Tick CSV, from MQL4\Files, sorted ascending by time |
| Input is tab delimited | false | true = tab, false = comma |
| Input has header row | true | Skip the first row of the input file |
| Col date time | 0 | Column index (0-based) holding a combined date+time, e.g. 2024.01.02 08:30:05 |
| Col bid | 1 | Column index holding the bid price |
| Bar minutes | 7 | Custom bar length in minutes (any positive value) |
| Output file name | RebuiltBars.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: Alerts · MT4 Script · MQL4 Source Code