MT4/MT5 History Export Script
Info
The MT4/MT5 History Export Script is a Script for MetaTrader 5 that a handy script to export historical data in the metatrader 4 format. This script addresses issues with historical data in MetaTrader 4 by allowing you to load detailed history from MetaTrader 5.
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 MT4/MT5 History Export Script
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
A handy script to export historical data in the MetaTrader 4 format.
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: advanced trade history exporter: mae, mfe, and time-based analysis - another powerful script for MetaTrader 5 traders.
A handy script to export historical data in the MetaTrader 4 format.Also recommended: mw download history - similar script with strong performance on MetaTrader 5.
This script addresses issues with historical data in MetaTrader 4 by allowing you to load detailed history from MetaTrader 5.
Setup:
- Load the script into the "terminal_data_folder\mql5\scripts\" directory.
- Load libraries into the "terminal_data_folder\mql5\include\komposter\" directory.
- Compile the script.
Setting History Depth:
- Go to "Tools - Options" (Ctrl+O) or the "Charts" tab.
- Specify the desired number of bars to export under "Max. Bars in the Window". For example, one year of M1 data is approximately 370,000 bars.
- Click "OK" and restart MetaTrader.
Selecting Instruments:
- Add the desired instruments to the "Market Watch" window.
- Hide any unnecessary instruments.
Running the Script:
- Drag the script to any chart.
- Set external variables:
- symbolslist: A comma-separated list of symbols (e.g., "eurusd,gbpusd"). Use "all" to include all symbols from "Market Watch".
- timeframeslist: A comma-separated list of timeframes (e.g., "m1,m5,m15"). Use "all" for all MT4 timeframes smaller than D1.
- barstodownload: The number of bars to export. Set to 0 to export all visible bars on the chart.
- Click "OK" and wait for the shutdown message. Monitor progress on the "Expert Advisors" tab.
Note: Large data sets may cause long processing times or memory issues.
Completion:
- Upon completion, the script displays a window with information and exits.
- Copy the folder path from the alert window to access the CSV files.
- Import the CSV files into MetaTrader 4 using "Quotes Archive - Import".
History of Changes:
2026.03.25:
- [*] If insufficient history is available for a given instrument/timeframe, the script now downloads and saves all available history instead of outputting an error.
2026.03.28:
- [+] Added the ability to write to "hst" files.
You may also like: create csv history file from mt5 for mt4 - excellent alternative for script users on MetaTrader 5.
Source Code
#property copyright "robotfx"
#property link "https://robotfx.org"
#property version "2013.03.28"
#property script_show_inputs
#include <komposter\checkhistory.mqh>
#include <komposter\string.mqh>
#include <files\filetxt.mqh>
#include <files\filebin.mqh>
input string main_properties = ""; // main properties:
input string symbolslist = "all"; // * list of symbols (or "all" marketwatch symbols)
.......
⚠ 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.