Master MetaTrader Log Files: Debug EAs & Fix Errors Fast

Learn to read MetaTrader 4/5 log files (Experts, Journal, Tester) to debug EAs, fix order errors, and troubleshoot platform issues like a pro developer.

master-metatrader-log-files-debug-eas-fix-errors

Introduction

Every MetaTrader user has faced the frustration of an Expert Advisor that simply won't trade, a custom indicator that draws nothing, or a backtest that ends with zero trades. The fastest path to a solution is rarely guesswork—it's reading the platform's own diagnostic output. MetaTrader 4 and 5 maintain detailed log files that record every action, error, and system message. Learning to interpret these logs transforms you from a frustrated user into a confident developer who can fix problems in minutes.

In this guide, you will learn exactly where to find each log file, how to read the timestamped entries, how to correlate error codes with MQL4/MQL5 return values, and how to inject your own diagnostic messages using Print() and Comment(). By the end, you'll be able to diagnose a silent EA, a failed order, or a crashing indicator without external help.

Prerequisites

Before you begin, ensure you have the following:

  • MetaTrader 4 or 5 (any build) installed and running on your desktop or VPS.
  • MetaEditor accessible from the Tools menu or by pressing F4.
  • A demo or live trading account (no funds required for log reading).
  • Basic familiarity with the MetaTrader terminal interface.
  • Optional: A test EA or indicator with known issues to practice debugging.

Step-by-Step Instructions

1. Locate the MetaTrader Log Files

MetaTrader stores logs in a folder structure under your platform's installation directory. The exact path depends on your operating system and whether you use MT4 or MT5.

For MT4 (Windows default):

  1. Open File Explorer.
  2. Navigate to C:\Users\YourUserName\AppData\Roaming\MetaQuotes\Terminal\.
  3. Inside, you will see folders with long hexadecimal names (each corresponds to a different broker installation). Open the folder for your current broker.
  4. Within that folder, locate the logs subfolder.

For MT5 (Windows default):

  1. Same parent path: C:\Users\YourUserName\AppData\Roaming\MetaQuotes\Terminal\.
  2. Open the broker-specific hexadecimal folder, then the logs subfolder.

Quick shortcut: In the MetaTrader terminal, go to File → Open Data Folder. This opens the broker-specific folder directly. From there, double-click the logs folder.

2. Understand the Three Core Log Files

MetaTrader maintains separate log files for different subsystems. Each is a plain text file with a .log extension, named by date (e.g., 20250215.log).

Log File Purpose Key Information
Experts Records all EA and custom indicator activity Print() output, order send results, initialization errors, deinitialization reasons
Journal Records terminal-level events Connection status, account changes, symbol updates, EA attachment/detachment
Tester Records Strategy Tester activity Backtest initialization, tick processing, optimization results, error details

3. Read and Interpret Log Entries

Each log line follows a consistent format: [timestamp] [message]. Timestamps use the local time of the terminal. Messages contain system text, error codes, or your own Print() output.

Example from Experts log (MT4):

2025.02.15 10:32:14.123 MyEA EURUSD,H1: initialized successfully
2025.02.15 10:32:15.456 MyEA EURUSD,H1: OrderSend error 130
2025.02.15 10:32:15.457 MyEA EURUSD,H1: deinitialized (stopout)

Here, the EA initialized, then attempted an order that failed with error 130 (invalid stops). The EA was then deinitialized due to a stopout. To fix this, you would check your stop loss and take profit calculations.

Common error codes you will encounter:

  • 130 – Invalid stops (SL/TP too close to market or incorrect).
  • 138 – Requote (price changed before order execution).
  • 145 – Modification denied (symbol restrictions).
  • 4108 – Unknown symbol (symbol not in Market Watch).
  • 4756 – Trade is disabled (AutoTrading off or broker restriction).

4. Inject Your Own Diagnostic Messages

The most powerful debugging technique is adding Print() statements to your MQL4/MQL5 code. Every Print() call writes a line to the Experts log.

Example in MQL4:

void OnTick()
{
   double bid = Bid;
   double ask = Ask;
   double spread = ask - bid;
   Print("Tick received. Bid: ", bid, " Ask: ", ask, " Spread: ", spread);
   
   // Your trading logic here
}

After attaching this EA, open the Experts log. You will see a new line for every tick. This confirms your EA is receiving price data and lets you verify variable values.

For visual feedback on the chart, use Comment():

Comment("Current spread: ", DoubleToString(spread, Digits));

Comment() displays a string in the top-left corner of the chart, updated each tick. It does not write to the log file, but it is invaluable for real-time monitoring.

5. Debug in the Strategy Tester

The Tester log is your best friend when backtesting. To access it during or after a backtest:

  1. Open the Strategy Tester (Ctrl+R).
  2. Select your EA, symbol, timeframe, and date range.
  3. Start the test.
  4. Switch to the Journal tab at the bottom of the Tester window. This shows live Tester log entries.
  5. For complete logs, open the logs folder and find the Tester log file for the current date.

Tip: In MT5, you can also view the Tester log by clicking View → Strategy Tester → Journal during a backtest.

Tips and Best Practices from Experience

  • Use descriptive Print() messages. Instead of Print("Error"), write Print("OrderSend failed for EURUSD. Error code: ", GetLastError()). This saves hours of re-reading.
  • Enable detailed logging in MT5. Go to Tools → Options → Expert Advisors and check "Print debug messages". This adds extra system messages to the Experts log.
  • Clear logs regularly. Log files grow quickly, especially during backtests. Delete old logs monthly to save disk space. You can do this safely while the terminal is closed.
  • Use the Experts tab in the terminal. The bottom panel of MT4/MT5 has an Experts tab that shows the last few hundred lines of the Experts log in real time. Right-click to copy or clear it.
  • For live debugging, run a separate instance. Open a demo account on a second MetaTrader installation to test EAs without risking your main trading setup.

Common Mistakes and Troubleshooting

Mistake 1: The Experts log shows nothing from your EA

Cause: The EA is not attached, AutoTrading is disabled, or the EA is not running on a chart.

Fix: Verify the EA is attached to a chart (look for a smiley face icon in the top-right corner of the chart). Ensure AutoTrading is enabled (button at the top of the terminal should be green). Check the Journal log for messages like Expert Advisor 'MyEA' loaded successfully.

Mistake 2: Print() messages appear in the Tester but not in live trading

Cause: The EA is running on a different chart or symbol than you expect.

Fix: Add this line to your OnTick() or OnStart() function: Print("Running on: ", Symbol(), " ", Period());. This confirms the chart context.

Mistake 3: Log files are empty or missing

Cause: The terminal has not generated logs yet, or you are looking in the wrong folder.

Fix: Restart MetaTrader, then perform an action that generates a log entry (e.g., attach an EA). Check the logs folder again. Use File → Open Data Folder to ensure you are in the correct broker-specific folder.

Mistake 4: Error code 138 (Requote) appears repeatedly

Cause: Market volatility or slow execution.

Fix: In your EA, add a retry mechanism with a small delay. Example:

int ticket = OrderSend(Symbol(), OP_BUY, 0.1, Ask, 3, 0, 0, "", 0, 0, Green);
if(ticket < 0)
{
   int error = GetLastError();
   if(error == 138) // Requote
   {
      Sleep(100); // Wait 100ms and retry
      // Retry logic here
   }
}

Never use Sleep() in OnTick() for live trading—only in the Tester or script.

Summary / Recap and Next Steps

You now have the skills to locate, read, and interpret MetaTrader log files. You can inject your own diagnostic messages with Print() and Comment(), and you know the most common error codes and their fixes. This knowledge alone will solve 90% of EA and indicator problems you encounter.

Next steps to deepen your debugging skills:

  • Practice by intentionally breaking a simple EA (e.g., use a wrong symbol name) and reading the log to find the error.
  • Learn to use the MetaEditor Debugger (F5) for step-by-step code execution—ideal for complex logic bugs.
  • Explore the GetLastError() function and its full list of error codes in the MQL4/MQL5 Reference.

Mastering logs is the first step toward becoming a self-sufficient MetaTrader developer. The next time your EA is silent, you won't panic—you'll open the log and fix it.

Frequently Asked Questions

How do I clear the Experts log in MT4?

Right-click inside the Experts tab at the bottom of the terminal and choose "Clear". This only clears the on-screen view; the log file on disk remains until you delete it manually from the logs folder.

Why does my EA work in the Strategy Tester but not on a live chart?

The Tester uses historical ticks and may not replicate real-time conditions like requotes or broker restrictions. Add Print() statements to your EA and compare the Tester log with the live Experts log to identify the difference.

Can I view log files remotely on a VPS?

Yes, use Remote Desktop (RDP) to access your VPS, then navigate to the logs folder as described. Alternatively, configure your EA to write logs to a file using FileOpen() and FileWrite() for easy retrieval via FTP or email.

Community

Clap for the article and open comments only when you want to read them.

0 claps0 comments

Related articles