History Depth Check - how far back your EA can read on each timeframe

History Depth Check - how far back your EA can read on each timeframe
Download ALL MT5 scripts (449)
YouTube Video Thumbnail



Similar MetaTrader Tools

History Depth Check - how far back your EA can read on each timeframe

Info

The History Depth Check - how far back your EA can read on each timeframe is a Script for MetaTrader 5 that an ea that needs two years of m5 data, or a long moving average on m1, can silently work with less history than you think. On a live chart the terminal keeps at most "Max bars in chart" bars per timeframe (Tools > Options > Charts).

Usage

This tool is typically used for enhancing chart analysis and decision making.

Platform

This Script works exclusively on MetaTrader 5 (both build 600+ and newer versions).

Setup

Place the downloaded file in MQL5/Scripts folder via File ? Open Data Folder in MetaTrader 5.


How to Install and Use History Depth Check - how far back your EA can read on each timeframe

1. Installation: Move your script file into the MQL/Scripts directory and restart the platform.

2. Execution: Drag the script onto a chart; it will perform a one-time action, such as closing all open orders or clearing chart objects.

3. Editing: Use MetaEditor (F4) to modify code, click "Compile," and verify no errors appear in the terminal before running.

4. Removing: Scripts stop automatically, but you can remove them manually by right-clicking the chart and choosing "Remove Script."

Frequently Asked Questions

Q: How are scripts different from EAs? A: Scripts execute a single action and then stop; EAs monitor the market and trade continuously.

Q: Can I assign a hotkey to a script? A: Yes, right-click the script in the Navigator, select "Set Hotkey," and define your preferred keyboard shortcut.

Q: Why did my script stop? A: Scripts are designed to stop immediately after finishing their programmed command; this is normal behavior.

What this tool does

An EA that needs two years of M5 data, or a long moving average on M1, can silently work with less history than you think.

Typical Use Case

This Script excels in automated trading and technical analysis on MetaTrader 5.

Compatible Platform & Setup

This Script works on MetaTrader 5. Place the file in the MQL5/Scripts folder and restart the terminal.

Description & Settings

Related: MetaTrader Backtest Data Validation: Broker Bar and Tick History Check - another powerful script for MetaTrader 5 traders.


Also recommended: Trade History Exporter: Detailed Closed Trade Analysis to CSV - similar script with strong performance on MetaTrader 5.


An EA that needs two years of M5 data, or a long moving average on M1, can silently work with less history than you think. On a live chart the terminal keeps at most "Max bars in chart" bars per timeframe (Tools > Options > Charts). With 100,000 bars, M1 reaches back about three to four months, M5 about one to one and a half years and M15 about four years (the exact span depends on the symbol's trading hours: FX trades about 24 hours a day, 5 days a week, indices fewer hours), even when the terminal holds many more years of history. Bars() and CopyTime() then return only the newest bars up to that limit.

This script prints a small table for each symbol you list:

the number of bars available on M1, M5, M15, M30, H1, H4 and D1;

the date of the oldest bar a program can read, and how many years that is;

"CUT by Max bars" when a timeframe stops at the limit while older data (more than 7 days older) exists on another timeframe or in the terminal's M1 history, with an estimate of the bar count needed to reach it;

a note when a series is more than 30 days shorter than the others but is not at the limit: the terminal holds less data for that series (not downloaded yet or not provided by the server).

Inputs:

Symbols: comma-separated list, empty = the chart symbol;

Show on chart: also writes the table with Comment(); the table is always printed in the Experts log.

How to read the example below: on this demo server EURUSD M30 stops in November 2018 because of the 100,000-bar limit, while H1 and D1 go back to 2011. An indicator that needs M30 data before November 2018 gets none. When a timeframe is cut, raise "Max bars in chart" and restart the terminal, or read the older history in smaller date windows.

On the first run the script may wait a few seconds per timeframe while the terminal builds the series. It does not trade, open charts or change any terminal setting. It only reads data, but it adds the listed symbols to Market Watch and may make the terminal download their history.

You may also like: Execution and Slippage Forensics for MetaTrader 5 Account History Audits - excellent alternative for script users on MetaTrader 5.

Source Code

#property copyright "RobotFX"
#property link "https://robotfx.org"
#property version   "1.00"
#property script_show_inputs
input string InpSymbols = "";
input bool   InpShowOnChart = true;
const ENUM_TIMEFRAMES TFS[] = {PERIOD_M1, PERIOD_M5, PERIOD_M15, PERIOD_M30, PERIOD_H1, PERIOD_H4, PERIOD_D1};
string TfName(const ENUM_TIMEFRAMES tf)
  {
   string s = EnumToString(tf);

.......

Leave your opinion, ask a question, share some knowledge

⚠ Limitations & Risk Warning

  • This tool is provided for educational and testing purposes only.
  • Past performance does not guarantee future results.
  • Trading involves substantial risk of loss. Use on a demo account first.
  • Results may vary depending on market conditions, broker, and settings.
  • We recommend thorough backtesting and forward testing before using with real funds.
© ROBOTFX Free educational tools by RobotFX. Use entirely at your own risk; we are not liable for any financial losses incurred.