Loading…

Timeframe Aligned Export

A model or spreadsheet that wants "what did the higher timeframes look like at this exact moment" for every row of a lower-timeframe series normally has to export each timeframe separately and join them by time itself - and that join is easy to get subtly wrong, because a lower timeframe bar's containing higher-timeframe bar is not a simple bar count division. Weekend and holiday session gaps mean bar N on H1 is not bar count/4 on H4 by arithmetic; only a time-based lookup answers the question correctly. This script does that lookup once, per row, with iBarShift() against each higher timeframe's own bar series, and checks that enough history is actually loaded for that timeframe before trusting the shift it returns - MetaTrader's own history for a timeframe you have not looked at recently on a chart can simply not extend back far enough, and a naive read would silently return whatever a too-small array happened to hold. A row whose higher-timeframe context could not be resolved safely is written with those columns left blank, and counted, rather than filled with a wrong value. Notes and limitations - If InpPrimaryTimeframe is itself H1, H4 or D1, that column set is still exported alongside the primary OHLC columns; the two will naturally read as identical or near-identical for the matching timeframe, which is expected, not a bug. - H1/H4/D1 context depends on the terminal actually holding that timeframe's history for the symbol. If it does not, and does not finish loading it during the run, those columns are left blank for the affected rows and counted in the summary Alert rather than guessed at. - Higher-timeframe columns show the bar that was open at the primary bar's open time, not necessarily a bar that has fully closed yet for the most recent rows near "now". - This exports historical alignment only. It does not update live as new bars form; run it again to refresh.

Script · MT5 · v1.0 · Free

About Timeframe Aligned Export

Timeframe Aligned Export is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message and can show data from another timeframe (MTF). It has 5 settings, such as Symbol, Primary timeframe and From date. MQL source code included.

Files in the download: TimeframeAlignedExport.ex5, TimeframeAlignedExport.mq5, TimeframeAlignedExport.txt.

Settings

SettingDefaultWhat it does
SymbolSymbol, blank = current chart symbol
Primary timeframePERIOD_M15Primary (row-per-bar) timeframe
From date0From bar open time (1970.01.01 = as far back as history allows)
To date0To bar open time (1970.01.01 = up to the latest bar)
Output file nameTimeframeAlignedExport.csvOutput file, written to MQL5\Files

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 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: Multi-Timeframe (MTF) · Trading Sessions · Alerts · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria