One of the best parts of MetaTrader 5 is that you can program automated trading strategies, called Expert Advisors (EAs), with the MQL5 programming language. Then you can test your strategies in the MT5 Strategy Tester.
Many traders use EAs to create fully automated trading strategies. However, EAs can also be used by discretionary traders to test new ideas, or in Incremental Automation.
Regardless if you go fully or partially automated, this post will show you how to get started with the MT5 Strategy Tester.
I'll show you how to install .ex5 and .mq5 files, how to do your first test, and how to find a MT5 programmer, if you don't know how to code.
The Difference Between .MQ5 and .EX5 Files
Let's start by taking a look at the two types of files that can you can install in MT5.
There are two different types of files because there is one file that humans can read and one file that that MetaTrader can read.
The file that human programmers can read (the .mq5 file) is not very efficient, so it's converted into a version that the computer can use efficiently (the .ex5 file). These files are also known by the following names:
- .ex5 = compiled, program or executable file
- .mq5 = source code file
When you add a .mq5 file to MT5, it will automatically be converted to a .ex5 file, when you open MT5.
If you purchase an EA on the internet, it will usually come in .ex5 format. This is because EA developers want to protect their hard work.
The .ex5 file hides their programming and doesn't allow others to see how it works.
However, if you create an EA yourself, or you work with a programmer to create an EA from scratch, the EA will be in .mq5 format.
Before working with a programmer, be sure that they will give you the .mq5 file. Having this file will allow you to make changes to your EA in the future.
How to Install an Expert Advisor in MT5
In order to start using Strategy Tester in MetaTrader 5, open MT5, then go to: File > Open Data Folder.
You can also hit Ctrl+Shift+D on your keyboard.
Once the folder is open, go to: MQL5 > Experts.
Then drag your MT5 Expert Advisor into the folder. The EA can either be in .ex5 or .mq5 format.
After the file has been moved, then restart MT5. You're now ready to start testing your EA in Strategy Tester.
How to Use Strategy Tester
Set Up Your Test
When MT5 restarts, go to: View > Strategy Tester. You can also press Ctrl-R on your keyboard to open Strategy Tester.
It will appear in a window at the bottom of your screen.
Here's what the settings do. They are listed in the order that they appear on the screen.
- Expert: Select the Expert Advisor you want to test from the dropdown.
- Symbol: Select the symbol you want to backtest.
- Timeframe: Select the timeframe you want to backtest.
- Dollar sign icon: Click on this icon to get details of the symbol selected.
- Date: Select the preset date ranges.
- Entire history
- Last month
- Last year
- Custom period
- First date dropdown: If you select Custom period, select the starting date of your test.
- Second date dropdown: If you select Custom period, select the ending date of your test.
- Forward: This allows you to do forward testing of your trading strategy. MT5 will split your data into 2 parts and only do optimization on the first part. Then it will test the optimized settings on the second part of the data. If you get similar results with both sets of data, then there's a higher probability that the settings are reliable and not subject to curve fitting. When forward testing is activated, you will see an additional tab that shows the forward testing results.
- No: Forward testing not used.
- 1/2: Half of the time period is used for the forward test.
- 1/3: One third of the time period is used for the forward test.
- 1/4: One fourth of the time period is used for the forward test.
- Custom: Use the dropdown to specify the first date of the forward test.
- Delays: You can select from several delay times to simulate delays between the time that MT5 gets a trade signal and the time the trade actually gets executed. This is useful if the connection to your broker is slow.
- “Select delay…” Button: This can be used to include other factors that might affect profitability like slippage, non-tradable time periods, margin and commissions.
- Modeling: You can select how ticks are generated. You can find more information on that here (it's pretty complex).
- Deposit: Adjust your initial deposit and deposit currency.
- Leverage: Choose the leverage you'll be using in live trading.
- Optimization: Choose the algorithm type you want to use. There are different ways that you can optimize your EA by having MT5 run through a series of values for each of your settings until it finds the best setting. Select the inputs you would like to optimize on the Inputs tab. You can read more about optimization here.
Start Your First Test
Once you've setup the test, click the green Start button. If you've checked the “visual mode…” box, the Strategy Tester Visualization window will open and show you the backtesting trades on the chart.
Use the slider to increase or decrease the speed of the test. This will allow you to watch your trades and see if your EA is working as you expected.
If you didn't check the “visual mode…” box then the test will run without seeing the trades on a chart. The best way to see the progress of your backtest is to flip to the Graph tab.
That will allow you to see live update of your equity and account balance.
Review Your Results
Once your test has completed, it's time to review your results. Go to the Backtest tab to see the stats on your test.
Where to Get MetaTrader 5 Expert Advisors
There are many ways to get a MT5 EA, but here are a few good places to start.
There are also many other websites that sell EAs and some offer free EAs for download.
If you have an idea for a trading system or EA, you can also create your own EAs.
How to Find a MT5 Programmer
The good news is that you don't have to learn programming…if you don't want to. You simply have to explain your strategy to a programmer and have them create the EA for you.
I created a list of Forex programmers here. Talk to them and see if any of them are a good fit.
Be sure to read the guide in the beginning to find the best programmer for you.
Learn to Program Yourself
If you would like to learn MQL5 programming, then start with the official MQL5 docs.
The best way to learn programming is to choose a simple project, then learn through trial and error.
For example, you could start off by programming a simple EA that opens a long trade when price closes above a moving average and closes the trade when price closes below the moving average.
…and the opposite for short trades.
It also helps to find free code on the internet, study how it works and make simple changes to the code. You might have to spend a couple of weeks learning how to code, but it can really pay off.
When you can code for yourself, you can test trading ideas, without paying for a developer to create the EA for you.
A final word of caution. Be sure to check, and double check every EA you install.
There can be bugs in the programming, which can have disastrous results. Even if you run an EA through the Strategy Tester, the results in live trading can be different.
So even if an EA does well in backtesting, always test it in a demo account for a few months before you put it into live trading.
But all of that testing can be worth it, if you can find an EA that will help you make profits while you're away from your computer.