Log files are written records of all trading activity in MetaTrader. Whenever a trader submits an order, modifies a stop loss or connects to the broker, MetaTrader notes everything that happens along with the time.
We use log files to reconstruct a sequence of events when expert advisors run on a live account. Knowing the order in which things happened helps us to determine why an EA may not work properly.
Consider the logical steps where you want to go to the grocery store. If I were writing software to do this, my log file might read something like this:
1) Find my car keys
2) Find my wallet
3) Get in the car
4) Drive to the grocery store
5) Buy groceries
If my log file only says “find my wallet” and “get in the car”, I intuitively know that something is wrong. Why would the software not work when I get in my car? Because I don’t have my keys.
The log file helps your MQL programmer think along the same lines. When the log says, “calculate the entry rules” and the log only talks about the exits, it’s clear that the flow of the program doesn’t match the design intention.
Log files only come from the computer where the expert advisor runs. When a problem inevitably arises, your programmer will request that you send the log files from the computer where you’re running the EA. This is unfortunately a necessary part of the debugging process.
We do all of our quality assurance testing in the MetaTrader backtester. Although this usually catches the most obvious bugs, new errors will always pop up while forward testing the EA. The log file is what helps connect us to the problem, even though it happened on another computer.
Find your MetaTrader 4 log file
MetaTrader keeps two sets of log files. The most basic logs are located in YOUR BROKER NAME\logs. Most of our clients navigate here accidentally and assume it’s the file that we need. Expert advisors cannot write to this log file, so it unfortunately doesn’t do us much good.
Locating the correct log file for your programmer will vary based on your operating system. Anything in capital letters changes based on your personal information.
Windows XP and Windows Server 2003 users can find the logs in C:\Program Files\YOUR BROKER NAME\experts\logs
Expert advisors that run on Windows Vista or 7 have to put in more effort. Those log files are found in
C:\Users\YOUR USER NAME\appdata\local\virtualstore\Program Files (x86)\YOUR METATRADER INSTALLATION\experts\logs.
The part that confuses most Windows 7 users is that when they navigate to the folder with their USER NAME, the appdata does not appear as an option. The easiest trick is to double click on the current folder name at the top of the screen. Once you’ve clicked, the entire directory name will appear. If you type “appdata” after the final backslash and push enter, the window will navigate to the correct location. You can then continue clicking until the log file appears.
The name of the file corresponds to the date. The format is year, month and date (YYYYMMDD). Today is January 23, 2012, so the log file for today is named 20120123.log.
Finally, log files are often enormous – 50 MB or more. Please right click on the file and select “Compress” or “Send to, Zip File”. Sending the zip file can reduce the file size by 80% or more.
If you need the log files produced during a Strategy Tester test look in
C:\Program Files\YOUR BROKER NAME\tester\logs
hi there
I found interesting this discussion on log files.
Do you know if is there a log analyser/expert advisor that catches automatically the log file into a specific mt4 path, and given some wordkeys, display them?
I am actually looking for a software that looks for in my place for error into the mt4 log file.
Instead of personally looking everyday for “off quotes”, “account not valid”, “context trade busy” and etc errors, I would like to retrieve these notices by email.
Do you know about a software like this ?
Hi luca,
Thanks for the comment. We have in house software that Chris Zimmer likes to call the “Get Log O-matic”. It’s a simple program that searches through various directories and finds all MT4 log files.
This software could be modified to grab the log files, then parse them and search for errors. How often do you wish to receive email notifications? Please email me more details – info@onestepremoved.com.
Hi Shaun,
don’t you know about any trick to force mt4 into saving the log file to some other path than \experts?
The reason is: I work with more mt4 instances spread across my LAN.. I used to sync them on demand (i.e. after every major recompile) with Synkron and it’s been PITA.. Nowadays I use network shares: \experts, \templates, \sounds and \profiles\shared, and map these shares as symlinks to all my locally installed mt4s. It works like a charm; the only “problem” is the MT4 experts log file is named with plain date, and just that! As the entire \experts directory is symlinked, all the instances try to write into the same file. I could symlink the \indicators, \libraries, \include and \scripts dirs separately, leaving \logs local.. but that leaves me with the necessity to symlink every EA source and binary separately as they reside in the root of the damn folder 🙁
Honestly, it’s not a big problem… the instance fired up first writes to the log, and the other terminals don’t even throw any error msg and their local logging in their own terminal is unaffected. But it’s not clean… i guess sharing the mqlcache.dat files perhaps isn’t either 😉 but it doesn’t hurt the mind since there’s no visible effect at all.
It would be perfect for me to find a way to change the path where the expert logs are saved.. but I guess it’s impossible, as the mt4 binaries are packed….. or, can you advise some other way of keeping all stuff in sync?
Thanks for the excellent stuff you’re bringing to us!
Best,
Tom
Hi Tom,
The only “trick” is to write your own log files. We do that on occasion, but it’s usually not worth the hassle. The obvious advantage is that you can name them whatever you wish.
That’s a very clever solution that you mentioned about running MT4 on a network. Great idea!
Hey Shaun,
thanks for this post. It was very helpful. My problem is, that the Metatrader(4) does not flush the logs to a file very often, so I have to close it, to read the entire logs. I hope there is a way to force-flush logs, so they can be accessed “live”. I only found this little code here: http://forum.mql4.com/38788 But it doesn´t work for me (in FindWindowA(i,log) the i is not accepted). Do you know any solution? Even creating my own log is not working as good as Print, because there are no dynamic parameters. So if I want to log variables lets say like this: int, string, string, bool, I can´t do it, because my own log-function does not accept these parameters…
Thanks in advance for any help,
Paul
Hi Paul,
Closing and reopening MT4 is the only quick and easy way to get the data. It’s a real pain.
Thanks Shaun! Too bad. I´m running MT on a remote server and work mainly via console. So restarting is not too practical. You said that you implemented your own logging function. Since my last question, I found that Templates are supported. Do you use templates for logging and do you have any meaningful examples?
Thanks again and greetings,
Paul
We use the generic log feature in MT4, so no templates or examples.
Hi Shaun,
I have a different problem with logfiles. I just want to keep them.
I frequently use the Print statement to write comment to the MT4 logfile to trace the logic of the Expert Advisor I am working on.
This works fine. The problem is that these logfiles work with a roll on/roll off system. So only the last 7 logfiles are stored on my computer. I wonder whether this is caused by some parameter in MT4 that I can change? Or do you know another solution that saves all my logfiles?
Thanks!
Not that I know of. Have you look in the AppData folder? To my knowledge, it should store everything.
If you want to view the Expert Advisor Log in MetaTrader, it’s in the Expert tab of the terminal.