An automated trading system is an algorithm written in a particular programming language whose task it is to enter, close and manage trading positions under prescribed conditions or, where appropriate, to perform other tasks.
It is nothing else than tens, hundreds or even thousands of lines of text in code that the trading platform translates into its language and on the basis of which it does what the code says.
You don't have to be a programmer or coder to use software robots or automated trading systems.
However, if you want to be a programmer, then Metatrader platform provides facilities for creating and testing such systems without paying for a separate platform.
However, you do need is the knowledge of the programming language.
Metaquotes Language or known by its short form, MQL, is the programming language of Metatrader 4.
In fact, the module for the creation and editing of automated trading systems, but also of the indicators and other programs designed to run in MetaTrader, comes directly with the platform and is called the MetaEditor.
To install an Expert Advisor for automated or algorithmic trading, follow these steps:
Open the MT4 platform
Select ‘File’ from the main menu
Click on ‘Open Data Folder’ to bring up a new folder panel
Select the ‘MQL4’ folder, followed by the ‘Experts’ file
Drag and drop your EA file(s) into this folder
Restart MetaTrader 4 for your changes to take effect.
Expert Advisors are very powerful instruments that can be added to the Metatrader 4 Platform to improve trading.
They are additional software, you can see them as “plugins”, that add to the trading client.
There are many types of Expert Advisors and for various goals.
You can use an EA for:
Chart Management
Order Management
Automated Trading
Risk Management
Many More other tasks
The type of EA is limited only by the creativity of the programmers.
Traders can use EA to manage their charts.
For example they can use an EA to:
Load Multiple Charts
Change Chart automatically
Take screenshots
Close Charts
This kind of use can save time with repetitive tasks.
You can use an EA to manage your orders and bypass the manual process of clicking in the platform.
You can for example:
Open multiple orders at once
Update multiple orders at once
Close multiple orders at once
Some operations can require several click and when they are repetitive an EA can really help.
This is probably the most interesting task that you can do with an EA, trading!
An EA can follow a strategy and execute it automatically, without breaks.
A developer can program an expert advisor with a set of rules so that the EA will continuously trade following these rules.
This means several advantages for the trader.Expert Advisors For Risk Management
Risk Management is one of the most important aspects of trading.
EA can follow specific rules of risk management and update your trades accordingly
Some powerful tasks that they can perform are:
Auto Close, they can close trades whether these do not meet rules of order management
Partial Close, if you want to partially exit a trade
Trailing Stop, you can move the stop loss to follow the price, limiting losses and securing gains
Although they can be similar for certain taks, Indicators don't have the ability to execute trade operations like EA has.
EAs can submit, modify and cancel orders, while Indicators cannot do any change related to orders
You can add Expert Advisors to your Metatrader 4 or 5 to expand the features of the trading platform.
EA can be very simple and also very complex, depending on their goal and ease of use.
If you ever been using MetaTrader 4 platform I am sure at some point you faced some issues. As a programmer I know that any software can fail from time to time, but most computer programs are designed in such a way that they will print out error, warning or any other informational messages for the user so (s)he could understand what’s going on.
Earlier I have wrote about troubleshooting expert advisors on MetaTrader 4, but another important thing is to know how to properly read log files to find the cause of the problem.
If you are one of those users who hit their computer every time they face trouble with any of the Expert Advisors, indicators or scripts on MetaTrader 4 platform, I am sure you’ll find this blog post very useful.
Being an MQL4 programmer for the last 7 years I know pretty well how to identify what’s wrong with one or the other MT4 app, but I also do know that many people don’t know how to do this. I literally receive hundreds of email messages every month where people face trouble with some MT4 EA and they cannot figure it out.
Do not get me wrong, but it looks like the majority do not even try to find what cause of the problem, and I must say that’s understandable because there’s not much information about how to do this.
So let’s dig in. I would be wrong if I say that MT4 will record all your activity and later you can track down what was wrong at a certain moment, but I am definitely right if I’d say that MT4 will log the most important actions. In most cases that’s more than enough to understand what’s going on.
There are three types of log messages in the MetaTrader 4 platform and they are separated in different tabs at the bottom of the terminal, the Experts tab and the Journal tab, and another Journal tab in the MT4 Strategy Tester. But in this article, I am going to talk about the messages in the Experts and Journal tab. I will leave backtesting log messages for another article
Experts and Journal tabs at the bottom of the MT4 client terminal. This is where MetaTrader logs all of the messages to inform the user what’s going on.
All those messages are also written to special log files. We will get to that later. But first, let me show you what you can find in the Experts and Journal tabs which in most cases helps to identify the cause of any EA trading problem without the need to dig deeper into the log files.
The Experts tab holds messages associated with the Expert Advisors, Indicators or Scripts you are running in the MT4 terminal.
For example, when the trade open request is sent by the EA, it will always be reported in the Experts tab. The same applies for any other trading action performed by the EA or Scripts. Indicators are not allowed to perform trading operations, they cannot open, modify or close the trades, but anything related with MT4 Indicators will also be logged in this tab.
Obviously, any EA, Indicator or Script can be programmed to print out custom messages as well. These messages will always appear in the same Experts tab too. However, you can clearly see which messages were printed by an EA and which were printed by the MT4 terminal to inform about something related to the EA.
Two different types of messages in the MT4 Experts tab.
In the picture above you can see two messages have a “yellow triangle” image on the left while others have a “gray circle” image. The ones with the “gray circle” image are printed by the EA. In other words, EA was programmed to print them in order to give more information to the user about what’s going on or what has happened at that certain moment. It’s kind of EA telling you what it is doing.
Imagine a security guard visiting each floor of the building and filling in some special journal about his activity. Floor 1, checked at 10:02 AM. Floor 2, checked at 10:04 AM. Floor 3, checked at 10:06 AM, etc. Anyone who will read his journal later will know which floors he has checked and at what time.
The “yellow triangle” picture indicates that this message is related to some sort of a trading operation and it was printed by the MT4 client terminal, but it kind of came from the EA as well. In other words, EA does not have any choice to avoid printing these messages. So any time EA performs a successful trading operation (like trade open, close or modification) it will be logged by the MT4 with that “yellow triangle” on the left.
Imagine additional security guards on each floor filling in their journals as well about that main security guard visiting them. Security guard on the 1st floor fills in his journal “Main guard visited 1st floor at 10:02 AM”. Then the second guard fills in his journal “Main guard visited 2nd floor at 10:04 AM”.
In the example above you saw one “yellow” message is about the trade opening and the other is about trade modification. There is no way for the EA to avoid printing these messages.
Now let’s take a look at how you can find out which EA actually printed the message.
This picture shows that messages in the Experts tab were printed by two MT4 apps.
As you see Experts tab has two columns. The first one is “Time” and there is no need for any explanation there. I will just mention that this is the time of your computer. So if your broker server’s clock (in the Market Watch window) is on a different timezone, its time will not match with the time printed in the Experts tab.
The second column says “Message“, but it kind of holds more than that. You can notice that the message starts with the name of the EA (or indicator, or script) and in our example we see two different Expert Advisors printing messages. “LTC Client VIP v2.6” is the name of the first EA and “Myfxbook” is the name of the second EA (messages at the top are the most recent messages).
This way you can easily identify which EA printed the message and this basically tells you which EA performed one or the other operation. For example from this example above we can clearly see that the LTC Client EA opened a sell trade #18662944 of a lot size 0.85 on the EURAUD currency pair at a price of 1.38578. There are no doubts about that and no matter what other people can tell you the Experts tab messages don’t lie. This trade was opened by the LTC Client EA, period.
MT4 Experts tab shows on which currency pair or another instrument chart a particular EA was running.
Next, after the EA name, comes an instrument name of the chart on which that particular EA is running. From the picture above it is clearly seen that the LTC Client EA is attached to the EURUSD H1 chart.
Normally EAs are programmed in such a way that they will only trade for the same currency pair of which chart they are attached to, but in this case, Local Trade Copier EA is designed to open, modify and close trades on any pair. And as for the Myfxbook EA running on the same type of chart, it does not matter to which currency pair it is attached to, it will still do its job.
Important to note that MetaTrader 4 terminal does not allow to attach more than one Expert Advisor to any chart, so if you want to run multiple EAs on the same MT4 terminal you’ll have to open additional chart window for each EA.
Obviously, those can be chart windows of any currency pair or trading instrument. In our example above both EAs are running on EURUSD H1 type of chart window, but those are actually different windows, they are just of the same currency pair and time frame.
Actually, the fact that a user can run the same EA on other charts of the same trading instrument made it difficult to understand which EA actually printed the message, because they both show the same “EURUSD H1” (or whichever pair it would be) in the Experts tab. So to solve this problem I have improved my LTC Client EA to print a special unique ID of the chart window it is running on.
When Local Trade Copier Client EA prints messages in the Experts tab of the MT4 client terminal, it will add a special chart window ID to help the customer identify which EA instance actually printed the message. This helps in case you are running multiple EAs.
This instance of the Client EA has been assigned ID of 73588-6000-1. In case there would be other Client EAs running on the same currency pair name it would be impossible to tell which EA printed the message. But in my case both Client EAs would have different IDs assigned and it would help to identify who printed the message.
This ID consists of a special unique number (73588), the Magic Number assigned to the EA (60000) and a Signal Provider ID (1). If you happen to be a user of my Local Trade Copier software you’ll understand what this means
You can see that the “yellow triangle” messages do not have that ID and it’s because EA does not print those message by itself as I explained above. This is why there is no way for me to add such message ID, but it still helps with identifying other messages.
Messages from two different Expert Advisors in the Experts tab of the MT4 client terminal. Both apps use unique message ID which helps to identify which EA printed the message even if they run on chart windows of the same instrument.
In the image above you can see two EAs loaded on different chart windows of the same currency pair and time frame (GBPUSD, M5) and both of those EAs printed messages in the Experts tab. Normally you would not be able to know which EA printed the message exactly because they both run on the same type of chart, but thanks to that unique message ID my apps are using, it is easy to identify which EA exactly printed the message. One EA uses message ID [84073-222-1] while the other EA uses message ID [30815-111-1].
If you happen to be an MQL4 programmer you might consider adding such feature to your EAs. It really helps when reading log files. If you ask how I generate a unique ID for each chart window my answer is, I don’t. I use special MQL4 function ChartID.
Generally, anything after the chart instrument and time frame (in the image below it is EURUSD, H1) is the message generated by the EA. Literally ,it can be anything, but do not freak out if you see lots of messages. If you want to know what’s going on on your MT4 account and what EA is doing you should simply read those messages to better understand the situation.
Messages from two different Expert Advisors in the Experts tab of the MT4 client terminal.
In the image above we can see Myfxbook EA printed the message “Statement uploaded successfully“. So what does that mean? My guess would be that EA wants to inform us that the statement was uploaded successfully to the Myfxbook database. Yep, simple as that
You’ll notice that in the Experts tab recent messages are at the top while older messages are at the bottom. So in other words you need to track messages from bottom to top to maintain the right order of messages. However, in the log file, as you’ll notice later, messages are sorted by time. This means older messages are at the top and you should read them from top to bottom.
If we look closer at the LTC Client EA in the image above we’ll see that it opened a sell trade, modified it and then printed a series of informational messages about the connection delay, price deviation, trade number of the master trade and also trade number of the copied trade so it would be easier to identify them if needed.
MT4 Experts tab shows error message code 134: Not enough money
What about errors? Using one of my EAs I have tried to open a trade of 800 lots. Let’s see what happened.
In the image above we see Trader on Chart EA generated a 134 error which means “Not enough money”, or in other words the lot size of the trade is too big for the current account balance. Now, this ToC app will also play a sound alert which lets a user know that something is not right, but by looking into the Experts tab we can easily identify the actual cause of the problem.
Furthermore, EA will also print a label on the price chart that holds the error code so more experienced users can quickly identify why the trade was not opened.
MT4 Expert Advisor prints label with error code on the chart.
Obviously, those error code labels are not available with all the Expert Advisors out there, this is something I have added to the code of my apps, so don’t expect other EAs to print this.
oe134 error code stands for “Open Error 134”. This means there was an error 134 when opening a trade.
Mostly all EAs these days prints at least an error code in the Experts tab so you can use that to identify a possible cause of the problem. Click here for a full list of possible error codes.
Here’s another example of an error message.
MT4 EA shows an error message about an incorrect entry price for BUY STOP pending order.
I have set the Trader on Chart app to place a BUY STOP pending order at 0.70000 on NZDUSD pair. However, this pending order was not placed because at that moment current NZDUSD Ask price was 0.75207.
Buy Stop pending order entry price should always be above the Ask price and it is impossible to place it below that price (it should be BUY LIMIT if to place it below Ask price). So for this simple reason, EA printed simple error message which says “Incorrect BUY STOP entry price 0.70000” and then there also are Ask and Bid prices logged for the record.
If all this sounds confusing to you I encourage you to read my blog post about market prices and different types of orders.
The other type of messages, anything that is not generated by MT4 apps, are stored in the Journal tab. These are the messages about MT4 platform upgrade, server connection, any attempt to perform trading action manually or automatically and obviously broker server responses that in many cases helps to understand what problem you are facing.
MT4 Journal tab logs error messages received from the broker server.
Remember that 800 lot trade? When broker server denied to open such trade a message about that was sent to the EA and we saw error message logged about this. But also we see that in the Journal tab there is another error message printed.
This one comes directly from the broker server and it would be printed regardless if that error was caused by manual trading or automated trading. This error message also clearly states that there was not enough money to open a buy order of 800 lots on NZDUSD pair at market price.
Journal tab is divided in two columns as well: Time and Message. No explanation needed for those, but what I like about error log messages is that they will show that little red circle image on the left side which helps us to spot error messages easily.
I must mention that I do not pay a lot of attention to the Journal tab, because mostly I trade using EAs and all the messages I need are in the Experts tab in that case. But you should not underestimate the information printed in the Journal tab. It is worth looking into if you cannot find an explanation anywhere else.
Log files basically store the same messages you find in the Experts and Journal tab, but obviously log files can store a lot more messages. When you close and reopen MT4 platform you’ll see that there will be no messages in the Experts/Journal tabs. They start fresh and any older messages are now stored in the log files.
Normally it takes some time for the messages to be transferred from the Experts/Journal tabs to the log files in real time, so if you want to find the most recent messages in the log files you should close your MT4 platform and give it a few seconds.
Messages from the Experts tab are printed to the log files located at \Data Folder\MQL4\Logs\
Messages from the Journal tab are printed to the log files located at \Data Folder\logs\ (these files does not help much when solving problems with EA trading)
“Data Folder” can be opened from your MT4 platform by going to “File -> Open Data Folder“. This is where you can find all the log files, EAs, indicators, script and other files stored.
Access MT4 Data Folder from the top menu.
Once “Data Folder” is opened you can navigate inside the MQL4 folder and then Logs folder. This is how Experts log files look on my computer.
MQL4 Experts Log Files in the Data Folder of MT4 platform.
You can see that each log file name is a date in a format YYYYMMDD. This helps easily to find what you are looking for. However, keep in mind that because of the time zone difference between your computer and your broker the log file from 20150413 might not have some messages from the previous or the next day.
So, if someone asks you to send them log file from 13th of April 2015 I recommend you to send three log files: 20150412.log, 20150413.log, 20150414.log. Basically, you should include log files from the previous day and the day after.
When you open a log file in any text editor like Notepad or Notepad++ you’ll see all messages that were recorded on that particular day. Important to note that there’s a limit to how long a message can be in the Experts tab, but there’s no limit (or it is quite big to notice) to how long messages can be in the log file. So if you find some message truncated in the Experts tab you can simply find a full message printed in the log file.
MT4 Experts messages printed in the log file.
In the picture above you can see an example of how this looks like. Basically, the format is the same as in the Experts tab except that “yellow triangle” images are converted to number 2 and “gray circle” images are converted to number 0.
Next we have Time, EA name, chart instrument and time frame, and finally the message.
Another easy way to access log files is to click a right mouse button anywhere inside the Experts tab and choose “Open“.
Click a right-mouse button anywhere inside the Experts or Journal tab and choose Open to access log files.
Doing this in the Experts tab will open you a folder with the Experts log files, while doing this in the Journal tab will open you a folder with the Journal log files.
Other choices from this menu are self-explanatory, but I particularly like these options: Copy, View and “Auto Scroll“.
“Auto Scroll” option is something I use rarely, but when I have trouble with some EA that prints enormous amounts of log messages, turning “Auto Scroll” can be helpful. It simply allows you to look at the messages instead of seeing them scrolling down fast automatically which does not even give you time to read what they say.
Copy option simply copies selected messages to a clipboard so you can paste them in other applications. This allows you to avoid sending full log file and simply copy and paste a few messages with error codes and send them to software support team. Of course, there might be cases when full log files is still required, but in many cases, only a few messages can help solve a problem.
View option allows you to filter through Experts log messages. Here’s the window it will open.
MT4 allows you to search for log messages by date and phrase.
What’s cool about this feature is that you can enter a phrase you want to find, choose a date range and MT4 will search all Experts log files to find any message that has your phrase.
In the example above I enter trade number 18831445, chose a date range of the last two days, and once I hit Request button I get messages with that particular trade number.
The trick here is very simple. In order to send many log files as one file, you need to pack them into a so called ZIP archive. This is very easy to do on any Windows machine. All you need to do is to open Logs folder, select files you want to pack, then click a right mouse button and from the menu choose “Sent to -> Compressed (zipped) folder“.
Packing MT4 Log files into a zip archive for easy delivery.
In the image below you can see how a .zip archive with compressed files look like. Seven log files compressed and packed into a single .zip file that can now be sent by email. It also save space. Those 7 files were 105 KB total and this .zip archive is 12 KB only.
7x MT4 Log files compressed into one ZIP archive.
To extract .zip archive you need to click the right mouse button on the file and from the pop-up menu choose “Extract All…“.
Extracting Zip archive with compressed and packed MT4 log files.
By simple reading messages in the Experts or Journal tabs on your MetaTrader 4 platform, you can easily identify and solve problems associated with your Expert Advisors, indicators and scripts. Many people quit too soon or waste days trying to solve the problem with the help of software support team. Obviously, there will be cases when you cannot solve the problem by yourself, but in most cases by just looking at those messages and using common sense can help you save hours of your time and get your MT4 apps running again.
All Expert Advisors created by EA Coder display a special error message code on MT4 charts when an error occurs during the open, close or modification phase of an order. If you see a message like ‘oe131’ on your chart when a new trade was supposed to be opened, you’ll know that an error has occurred.
Error message codes always start with two letters followed by an error code number. The error codes I use are the same as those used in the MQL4 programming language and are explained in detail on the MQL4 documentation page.
Error codes may start with oe, me or ce.
oe stands for “open error“, me stands for “modify error“, and ce stands for “close error“.
Take our previous example oe131. Now we know that it indicates an error during a trade open, with the code 131. If you look at the full list of error code descriptions, this one means “invalid trade volume”, which alerts us to check the money management settings that we have set for the Expert Advisor. This kind of error appears when a lot size is zero, if it is too small or if it is too big, because all brokers have lot size limitations. Some do not allow the lot size to be smaller than 0.1 while others allow lot sizes as low as 0.01. This varies among different brokers and different account types.
Usually Expert Advisors from EA Coder fix the lot size according to the broker limitations, but exceptions may apply because not all brokers report the correct limitation values for the EAs. An example of this is a broker reporting the minimum allowed lot size to be 0.01 while in reality it is actually 0.1. In a case like this, if you to set the EA to use a lot size somewhere between 0.01 and 0.09 it will fail to place orders as it won’t be able to fix the lot size because of it being reported incorrectly. Then you will get the oe131 error message printed on the chart.
Another example would be to get the oe133 error. This stands as “Trade is disabled” and it means that the broker does not allow to trade that pair. If this error appears even when customer tries to open trade manually on the same chart, then MT4 EA should be attached to a similar pair with the suffix. For example if you get this error on EURUSD, please look for pair name like EURUSDm or EURUSDFXF.
If you are able to open trades manually on the same pair it could be that your broker does not allow to use trading robots (EA’s) on that pair or account. Contact them for more info.
128 – Trade timeout.
129 – Invalid price.
130 – Invalid stops.
131 – Invalid trade volume.
133 – Trade is disabled.
134 – Not enough money.
146 – Trade context is busy.
Let’s take a look at another common error that you may receive. It would be printed on your chart as me130 which stands for “modify error 130” and means “invalid stops”. This tells us that the stop loss and/or take profit values are incorrect or too close to the current market price. The minimum distance between the market and stop prices are called StopLevel limitation; this value simply tells the EA what size in pips the limitation is. On 5 digit brokers this is reported as points and must be converted to pips. However that is something the user don’t need to worry about, because EA Coder Expert Advisors handle these things automatically. But if you get a me130 error, be sure to check the TP and SL values that you’re using.
128 – Trade timeout.
130 – Invalid stops.
146 – Trade context is busy.
You may get a ce146 error when EA tries to close an order. This indicates that a “close error” occurred whose code is 146. This means “trading context busy” and it is very common error, specially on older MT4 terminals when you have multiple Expert Advisors attached. EA Coder robots have an intelligent error handling mechanism built in and will do their best to avoid “trading context busy” errors even if you have multiple robots operating on your account. But in case you get one of these errors, just try to minimize the number of EAs running on the same account or set them to avoid performing trading operations at the same time if that’s possible with your EA.
128 – Trade timeout.
146 – Trade context is busy.
EA may need to delay a trading operation to avoid disrupting the MQL programming rules when an error occurs. It will retry the same trading operation if required and will have to wait somewhere between 1 to 5 seconds between each attempt. These are very logical rules of Metatrader programming and EA Coder trading robots obey them. See full list of execution errors.
In case there is a delay in performing a trading operation (whether it is opening, modifying or closing a trade) EA will print a small clock picture on the chart. This indicates that there was some kind of error and EA had to delay its operation for a few seconds to obey the rules and not overload the brokers’ servers.
When any error occurs, the EA will print a more detailed error message in the Experts tab at the bottom of the MT4 terminal. You can switch to that tab any time and scroll down to see a complete list of errors, warnings and informational messages. These can help to solve a range of problems quickly even if you don’t have a lot of experience in using the MT4 platform and Expert Advisors or custom indicators.
When you’re viewing the Experts tab you can click the right mouse button anywhere in that area and choose “Open”. This will open the log files folder for you. This folder contains files with the same messages that you see in the Experts tab, but from here you can access messages from previous days and weeks. Also, messages in the log files are presented in their full format and are not trimmed like some of the messages shown in the Experts tab when they are too long.
When you need to report an error to EA Coder, please describe the problem you are having in detail, include the trade numbers that you are having problems with, and make sure you attach any necessary files. It is very important that you send the log files from your \MT4-folder\experts\logs\ so that I’m able to investigate an error. Also please include screen shots of the chart where EA is running and if possible make sure that the problem is visible in the picture. This will help us provide you with more useful support.
You might notice that your log files folder is empty or doesn’t have any recent log files (the file names indicate the date they were created). In this case please carry out the steps described above which detail how to open the log files folder directly from the Experts tab at the bottom of your MT4 terminal.
Before you report a problem or request support for learning how an EA feature works, please refer to the instructional manual. This may help you solve your problem faster and you will also learn how to use the application better.
Our Expert Advisors have a special order labeling mechanism built in. It is activated when you run EA in the Strategy Tester of your MT4 and it will create label numbers for each order that is placed during a backtest. This helps to track your trades easily as you will see the order numbers above each trade on the chart.