Blog / Fix MT5 errors · MQL5 · Expert Advisors · Debugging
How to Read the MT5 Journal and Experts Logs to Find Bugs
Learn how to use MT5 Experts and Journal logs to identify EA errors, failed trade requests, connection problems and runtime bugs.
· 5 min read
When an Expert Advisor stops trading, opens an unexpected position or fails to execute an order, check its logs before changing the code.
MetaTrader 5 records EA activity, terminal events and trade operations. These records can help you identify whether a problem comes from your code, the platform, the broker's server or the trading environment.
The two most useful places to start are the Experts and Journal tabs. Here's how to use them to find the source of an EA problem.
1. Know Which Log to Check
Both logs are available in the Toolbox window. Press Ctrl + T to open it.
| Log | What it records | What to investigate |
|---|---|---|
| Experts | EA and indicator activity, including Print() messages and trade-related events |
EA logic, indicator errors and custom debug messages |
| Journal | Terminal and platform events, including connections and trade operations | Connection problems, platform events and server responses |
Suppose your EA generates a buy signal but doesn't open a position.
The Experts log can show whether the EA reached its order-submission code. The Journal can provide additional information about the platform and trade-server response.
Compare entries from both logs around the same timestamp. This helps you establish what the EA attempted and what happened afterward.
2. Find the Error at the Right Time
Don't read through hundreds of unrelated messages. Start with the approximate time the problem occurred.
- Open the Experts tab and find the EA's messages around that time.
- Switch to Journal and inspect entries from the same period.
- Look for errors, warnings, rejected requests and connection messages.
- Note the timestamp, source and message.
You can right-click a log entry and select Copy to save it for closer inspection.
To access older logs:
Right-click inside the Experts or Journal tab and select Open. MT5 opens the folder containing the relevant log files.
The main locations are:
MQL5\Logs\— EA and indicator logs.Logs\— terminal logs.
You can access these folders through File → Open Data Folder in MT5.
Log files are organised by date, so open the file corresponding to the day the problem occurred.
3. Recognise Common Error Messages
A log message doesn't always reveal the complete cause, but it tells you where to investigate.
| Message or symptom | What to check |
|---|---|
array out of range |
Array indexes, loop boundaries and array size |
invalid stops |
Stop distance, freeze level and current Bid/Ask |
not enough money |
Requested volume and available margin |
invalid volume |
Symbol's minimum, maximum and volume step |
no connection |
Internet connection, terminal status and broker server |
| Invalid indicator handle | Indicator creation parameters and returned handle |
CopyBuffer() returns fewer values than requested |
Copied count, indicator readiness and runtime error |
For example, an invalid volume response doesn't automatically mean you should reduce the lot size. First check the symbol's actual volume requirements.
Likewise, an array out of range error means you should inspect the index being accessed and confirm that the array contains the requested element.
4. Add Debug Messages to Your EA
Sometimes the existing logs don't show enough information to identify the problem. Add targeted messages around the code you're investigating.
MQL5 provides Print() and PrintFormat() for writing information to the Experts log.
For example:
void OnTick()
{
PrintFormat("EA running: %s, timeframe: %s",
_Symbol,
EnumToString(_Period));
// Add signal calculations here.
double fastMA = 1.08500;
double slowMA = 1.08450;
PrintFormat("Fast MA: %.5f | Slow MA: %.5f",
fastMA,
slowMA);
}The values above are illustrative. In a working EA, replace them with your actual calculated indicator values.
Place messages immediately before and after the operation you're investigating. This helps you identify the last step reached before the unexpected behaviour.
Avoid printing excessive information on every tick in a live EA. Too many messages make important errors harder to find.
Check failed indicator data requests
If your EA uses CopyBuffer(), log its return value and the runtime error when the requested data isn't available.
double maBuffer[1];
ResetLastError();
int copied = CopyBuffer(
maHandle,
0,
0,
1,
maBuffer
);
if(copied != 1)
{
int errorCode = GetLastError();
PrintFormat(
"CopyBuffer failed: copied=%d, error=%d",
copied,
errorCode
);
}
else
{
PrintFormat("MA value: %.5f", maBuffer[0]);
}This example assumes maHandle is a valid indicator handle created elsewhere.
ResetLastError() clears the previous runtime error before the operation. GetLastError() retrieves the last MQL5 runtime error but does not automatically clear it.
Capture the error immediately after the failed operation so you don't mistake an older error for the current one.
5. Check the Actual Result of Failed Trade Requests
A common debugging mistake is assuming that a successful CTrade::Buy() or CTrade::Sell() method call means the broker executed the trade.
It doesn't necessarily mean that.
Log the trade-server return code as well:
#include <Trade/Trade.mqh>
CTrade trade;
void OpenBuy()
{
bool sent = trade.Buy(0.10, _Symbol);
PrintFormat(
"Buy request: method_result=%s, retcode=%u, description=%s",
sent ? "true" : "false",
trade.ResultRetcode(),
trade.ResultRetcodeDescription()
);
}The return value tells you whether the method's basic request processing succeeded. ResultRetcode() and ResultRetcodeDescription() provide the trade-server response.
Some useful return codes are:
| Retcode | Meaning |
|---|---|
10009 |
TRADE_RETCODE_DONE — request completed |
10010 |
TRADE_RETCODE_DONE_PARTIAL — partially completed |
10016 |
TRADE_RETCODE_INVALID_STOPS — invalid Stop Loss or Take Profit |
10019 |
TRADE_RETCODE_NO_MONEY — insufficient funds or margin |
For more detailed monitoring of trade request events, you can also use OnTradeTransaction().
The important point is to distinguish between an MQL5 runtime error and a trade-server rejection. They are different problems and require different fixes.
6. Use Strategy Tester Logs When Backtesting
If the problem only occurs during backtesting, inspect the Strategy Tester logs.
After running a test:
- Open the Strategy Tester results.
- Select the Journal tab to inspect the testing agent's messages.
- Look for the first unexpected event.
- Compare its timestamp with the EA's behaviour.
- Check the orders and deals in the test report to see which trade requests went through.
For example, if your EA generates a signal but opens no position, the Journal and the report's orders show whether it submitted a trade request.
- If a request was submitted, investigate its parameters and server response.
- If no request appears, investigate the conditions preventing the EA from reaching its order-submission code.
Remember that Strategy Tester logs and live terminal logs are separate. Make sure you're inspecting the correct session.
A Simple Debugging Checklist
When an EA behaves unexpectedly, follow this order:
- Reproduce the problem and note the symbol, timeframe and approximate time.
- Check the Experts log for the EA's last messages.
- Check the Journal for related terminal or server events.
- Identify the operation that failed.
- Add targeted logging if the existing messages aren't sufficient.
- Correct the underlying cause and repeat the same test.
Save relevant log entries before clearing or closing them. They may be useful when comparing the original failure with the corrected behaviour.
Conclusion
The MT5 Experts and Journal logs help you identify what an Expert Advisor was doing when something went wrong.
Use the Experts log to investigate EA activity and the Journal to check related platform and trading events. Add targeted Print() or PrintFormat() messages when you need more detail, and always inspect trade-server return codes when an order fails.
The goal is not to collect more log messages. It's to find the operation that failed, understand why it failed and verify that the fix works.
With PositionAlpha's Fix an EA, you paste or upload the EA and describe the problem. The AI returns the complete updated .mq4 or .mq5 file and explains the problems it found and each change it made. Compile the result in MetaEditor and test it in the Strategy Tester and on a demo account before you rely on it.
Build a bot from your idea
Describe your trading idea and the AI writes MT4 or MT5 code for you to review and test, with a plain-English explanation and setup steps. Your first bot is free.