Loading…

Download History For All Symbols

Loading a terminal onto a new machine, or adding a batch of symbols to Market Watch, usually means clicking into each chart in turn and waiting for the history to trickle in before any indicator or backtest on that symbol means anything. Doing that by hand across fifty or a hundred symbols is tedious and easy to lose track of. The honest limitation, stated up front because it is the single most important thing to understand before running this: both MetaTrader 4 and MetaTrader 5 download history asynchronously. The terminal streams bars from the broker's server in the background, and no MQL script, this one included, has any call that starts a download and blocks until it is complete. The only tool available is iBars(), which does two things at once - it queues a background request if the data for that symbol and timeframe is not already cached, and it reports however many bars are cached at the instant it is called. There is no "download finished" event to wait for. This is exactly where naive versions of this idea go wrong. A script that calls iBars() once per symbol, prints the number, and stops has told the user almost nothing - it captured the bar count before the download had a real chance to run, often close to zero, and a user reading that as "this symbol has no history" would be wrong. This script instead polls: after the initial request it checks the bar count again every InpPollIntervalMs milliseconds, up to a ceiling of InpMaxWaitMsPerSymbol per symbol and timeframe, and stops early the moment the count between two polls stops growing. That is still not a guarantee of complete history - a slow broker server can still be mid-stream when the budget runs out - but the number reported is always the true count at the moment the script gave up, not a number sampled too early. The result is printed as one aligned table: one row per Market Watch symbol, one column per timeframe requested, values are bars available at the end of that symbol's wait. An optional CSV export writes the same table to the terminal's Files folder with an ISO-style timestamp in the filename, for symbol lists too long to read comfortably in the Experts log. Notes and limitations - This script cannot guarantee a complete deep history download. It can only request bars and report what arrived inside the wait budget. If a column looks short, the most reliable fixes are: run the script again (a second pass often finds more already cached from the first), open each symbol's chart directly and let it load in the foreground, or use the terminal's own history centre to download a specific date range. - Slower brokers, or a first run against a symbol the terminal has never seen before, may need a much longer InpMaxWaitMsPerSymbol than the default, or more than one run, before the numbers stop climbing. - A very long symbol list multiplied by a long wait budget and several timeframes can make the script run for several minutes. It checks IsStopped() throughout, so it can be aborted from the terminal at any time, and it prints whatever partial results it gathered before stopping rather than discarding them. - The bar counts reported are a snapshot at the end of each symbol's wait, not a live figure - history can keep arriving in the background after the script has finished and moved on to the next symbol. - Only symbols already present in Market Watch are scanned. Symbols known to the broker but not added to Market Watch are not touched.

Script · MT5 · v1.0 · Free

About Download History For All Symbols

Download History For All Symbols is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 11 settings, such as M1, M5 and M15. MQL source code included.

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

Settings

SettingDefaultWhat it does
M1falseRequest M1
M5falseRequest M5
M15falseRequest M15
M30falseRequest M30
H1trueRequest H1
H4trueRequest H4
D1trueRequest D1
Max wait ms per symbol3000Max wait per symbol/timeframe pair, ms
Poll interval ms250Poll interval while waiting, ms
Write csvfalseAlso write the table to a CSV file
Csv delimiter,CSV delimiter (first character is used)

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: Alerts · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria