Sourcetable Integration

Export MT4 to CSV

Jump to


    Mastering the art of exporting data from MetaTrader 4 (MT4) to CSV format opens up a world of possibilities for traders and algorithm developers. By converting your MT4 account history into a CSV file, you facilitate seamless integration with Excel, enabling comprehensive data analysis and the application of advanced trading strategies. On this page, we'll delve into the nuts and bolts of what MT4 is, the step-by-step process of exporting MT4 data to a CSV file, and the practical use cases for this capability. Additionally, we'll explore an alternative to CSV exports for MT4 using Sourcetable and address common questions related to the export process. Discover the value of this vital trading tool and how it can enhance your market analysis and predictive capabilities.

    What is MT4?

    MetaTrader 4, commonly known as MT4, is a widely used platform for trading Forex, which also facilitates the analysis of financial markets. It supports algorithmic trading through the use of Expert Advisors and provides advanced technical analysis tools. MT4 is designed to offer a flexible trading system and includes features such as mobile trading applications, which allow users to trade on the go, and compatibility with any browser across different operating systems like Mac OS, Linux, Android, and iOS devices.

    As a client terminal, MT4 enables users to effectively control and manage their open positions and utilize several types of trading orders, including Market orders, Pending orders, Stop Loss, and Take Profit. The platform is responsible for setting execution prices for all trade operations and specifically executes Stop Loss and Take Profit orders for open positions. For charting purposes, MT4 draws history charts based on BID prices and can also display the ASK price for the latest bar if the "Show Ask line" setting is enabled.

    In terms of data handling, MT4 works with a variety of data types such as boolean, integers, floating-point, strings, colors, datetime, and enumeration for basic operations, as well as structures, classes, and abstract data types for object-oriented programming (OOP). This allows for robust data management and visualization within the platform, catering to the diverse needs of traders and developers alike.

    How to Export MT4 to a CSV File

    Method 1: Manual Export using HTML Files

    The first method to export MT4 account history involves generating HTML files. Access the account history by using the "account history" tab within MetaTrader 4, which can be done by pressing CTRL+T or selecting "Terminal" from the menu. Once the account history report is visible, it can be saved as an HTML file. After saving, manually copy the text from the generated HTML file and paste it into an Excel file to proceed with data manipulation as desired.

    Method 2: Using a Script to Export to CSV

    For a more automated process, users can export the account history to a CSV file using a Script. The Script, which is an ex4 file type, should be placed in the MQL4/Script directory of the MetaTrader 4 platform. Once added, this ex4 script can be used to automatically transfer the account history from HTML to CSV. After successful export, the CSV file can then be easily imported into Excel for further analysis or record-keeping.

    Sourcetable Integration

    Import MT4 Data Directly into Sourcetable

    For traders and analysts utilizing MT4, the prospect of exporting data to CSV files and then importing it into a spreadsheet program can be a time-consuming task. Sourcetable presents a seamless solution by allowing users to directly sync their live MT4 data into its system. This process eradicates the need for the cumbersome export-import cycle, streamlining data management and analysis.

    Sourcetable's ability to automatically pull in data from multiple sources, including MT4, transforms the way users interact with their trading information. By using Sourcetable, traders can leverage the platform's familiar spreadsheet interface to query and manipulate their live data with ease. This not only saves valuable time but also ensures that the data is always current, providing users with real-time insights that are crucial for making informed trading decisions.

    The integration of Sourcetable in your workflow is a smart move towards efficient automation and enhanced business intelligence. Its robust system is designed to handle the dynamic nature of trading data, allowing for continuous synchronization and immediate accessibility. The advantage of using Sourcetable over traditional CSV exports is clear: it offers a direct, automated and integrated approach to managing your MT4 data, giving you an edge in the fast-paced trading environment.

    Common Use Cases

    • M
      Sourcetable Integration
      Exporting the last 10 OHLC candles on a minute timeframe for analysis or record-keeping
    • M
      Sourcetable Integration
      Exporting the open price of the new candle as soon as it forms for real-time trading strategies
    • M
      Sourcetable Integration
      Generating MT4 account history reports for performance review or compliance purposes
    • M
      Sourcetable Integration
      Automating the export of MT4 account history to a CSV file for ease of data manipulation in Excel
    • M
      Sourcetable Integration
      Using scripts to export real-time quotes for multiple symbols into separate CSV files for comprehensive market analysis

    Frequently Asked Questions

    Can I export my MT4 account history to a CSV file?

    Yes, MT4 account history can be exported to a CSV file.

    What are the methods for exporting MT4 data to a CSV file?

    There are two ways: generating reports and saving them as an HTML file to manually copy to Excel, or using a script to automatically export the account history.

    How do I use a script to export MT4 data to a CSV file?

    Add the ex4 script to the MQL4/Scripts directory, and the script will export the account history to a CSV file, which can then be imported into Excel.

    Does MT4 support real-time exporting to a CSV file?

    MT4 does not natively support exporting to a CSV file in real-time, but a script can be used to perform this action.

    How can I export quotes for multiple currency pairs using a script?

    The script exports quotes for multiple pairs by setting the Pairs parameter and the delimiter parameter in the code.


    Whether you're manually copying account history to Excel or using a script for automatic conversion, exporting MT4 data to CSV is a straightforward process that can enhance your data analysis capabilities. By following the step-by-step guide, you can efficiently export historical data in various timeframes, ensuring you get exactly what you need. Remember, for the best performance, it's recommended to use a script and avoid using a CustomIndicator for file I/O operations. For those seeking to streamline their workflow even further, consider using Sourcetable to import your data directly into a spreadsheet. Sign up for Sourcetable today to get started and elevate your trading analysis with ease.

    Start working with Live Data

    Analyze data, automate reports and create live dashboards
    for all your business applications, without code. Get unlimited access free for 14 days.