Backtesting Trading Strategies Mt4
The great part about MetaTrader 4 is that you can create automated trading strategies called Expert Advisors (EAs) and backtest them in the built-in Strategy Tester. If a strategy works well after thorough testing, the next step is to start testing it in a demo account to see if it works in real-time market conditions.
- Backtesting Trading Strategies Mt4 Login
- Backtesting Trading Strategies Mt4 Tutorial
- Backtesting In Mt4
But using the Strategy Tester can be confusing when you use it for the first time. The first time I used it, I thought it was broken đ
Backtesting, through strategy tester in MT4, certainly differentiates a good strategy from worst. Scalping and short-term trading strategies require an automated trading system as it needs quick in and out. A good strategist can only make maximum use of an automated trading system.
So in this video, Iâll show you how to go from beginner to pro, when it comes to backtesting automated trading strategies in MetaTrader 4. Learn how to do a quick test, use the strategy optimizer and use visual mode.
If you want to learn how to use the MT5 version of Strategy Tester, you can find that tutorial here. You can also learn more about MT4 by going through these tutorials.
The text version of the video is provided below the video.
- 3rd party software integration with MT4 is a neat solution because that way you can backtest strategies that use custom proprietary indicators as well. The F12 function key method MT4 has a built in function to shift the chart by 1 candle at a time.
- Backtesting with MT4 - Strategy Tester You can access the strategy tester in MetaTrader 4 (MT4) by pressing CTRL and R or going into the View section up the top and clicking on Strategy Tester. For a quick test, you can turn off visual mode and you can also speed or slow the visual mode testing.
How to Setup the MT4 Strategy Tester
Before you do anything in Strategy Tester, make sure that the EA you want to test is installed. You can do this by going to: File > Open Data Folder.
From there, open this folder: MQL4 > Experts. Then drag your EA file into that folder.
You can also check to see if the EA is already installed.
Once your EA is installed, restart MT4.
Now that your EA is installed, open MT4 and click on the Strategy Tester button. This feature is NOT available in the mobile version of MT4.
The Strategy Tester window will appear at the bottom of your screen. You are now ready to do your first test of your EA.
How to do Your First Backtest in the Strategy Tester
Here is an explanation of the settings:
- In the first box, select your EA from the dropdown list.
- Symbol: Select the symbol that you want to backtest on.
- Model: Use the default Every tick setting.
- Use Date: Leave this box checked and select the From and To dates that you want to use for this test.
- Visual mode: Leave this box unchecked for now. You can also ignore all of the settings immediately to the right of this box. They will be grayed out anyway.
- Period: Select the timeframe chart that you want to test from the dropdown list.
- Spread: Leave as Current.
- Expert properties button: Click on this button to change the settings of the EA.
- Symbol properties button: You wonât have to use this button in this tutorial.
- Open chart: Only click this button after a test has been completed.
- Modify expert: This is only used to modify the source code of the indicator. You wonât need this for your first test.
- Optimization: Uncheck this box. We will get into optimization later in this post.
Once everything is setup, then click on the Start button.
Alright, this is where things may get confusingâŚ
When you first start the test, the green bar will move from left to right. This first pass shows that the data is being loaded.
Then the green bar will reset and start moving from left to right again. This is when itâs actually testing.
You wonât see anything happening on the chart. MetaTrader 4 is testing in the background.
This is the fastest way to backtest because it doesnât have to constantly update the chart. If you want to see the results in real-time, go to the Graph tab at the bottom of the screen. That will show you the results of every trade, as it happens.
You can also look on the Report tab to see the stats on your test.
The Results tab will show you all the trades that were taken.
Once the test is completed, you can click on the Open chart button and you will see of the trades that were taken.
This chart can help you understand if your trades are being executed as you expected.
When you double click on a trade in the Results tab, and you have the chart marked with your trades open above, the chart will jump to that trade.
Thatâs the fastest way to backtest your EA.
Another way to backtest is to use visual modeâŚ
How to Use Visual Mode in Strategy Tester
Visual mode will open a chart and show you the execution of every single trade.
In order to use visual mode, simply check the Visual mode box before you click the Start button on your test.
This is what youâll see on your chart.
Once the data loads, youâll see the chart and the price will start changing. In order to speed up the process, move the slider next to the visual mode box all the way to the right.
Even at âfull speedâ the chart will move pretty slowly. So you might wonder what the benefit is to using this mode.
The primary benefit is seeing how your strategy executes in almost real-time.
When you look a the code or to a standard backtest, it can be difficult to see where the EA is making mistakes or how your settings are affecting the results.
But sometimes when you see trades executing as price moves, the issues become very clear.
Therefore, this method of testing is not geared for speed, but itâs a way to visually spot issues or optimizations.
MT4 Strategy Tester Optimizer
Now that you have a good feel for how the Strategy Tester works, you can start optimizing some of your parameters.
It would be great if there was some sort of fancy AI powered optimization algorithm, but unfortunately there isnât.
Strategy Tester uses a very simple iterative process of trying different EA settings and showing you the results.
Backtesting Trading Strategies Mt4 Login
But that can be a good thing. When you use an AI, you donât quite know what itâs doing in the background.
With the MT4 optimization process however, you know exactly whatâs happening and identifying the best settings is a straightforward process.
To use the optimizer, click the Optimization box before you start the test.
The way that MT4 optimizes your EA settings is by allowing you to set a starting, ending, and step up value for each of your EA settings. For example, here are the settings that are available for the EA that Iâm using in this example.
For each setting, you can set the following:
- Checkbox: The parameters that are checked are the ones that will be optimized.
- Value: The value used for normal testing.
- Start: The start value used for optimization. This value is not actually tested.
- Step: The increments that are used in each of the tests. In this example the step is set to 10, so the value for this input will increase by 10 on each successive test.
- Stop: This is the final value that will be tested during optimization.
Backtesting Trading Strategies Mt4 Tutorial
Just to clarify how this worksâŚ
If you use a starting value of 10, a step value of 10 and stop value of 30, MetaTrader 4 will test 20 and 30 only. It will not test the starting value of 10.
Also keep in mind that the more inputs you test, the longer your optimization tests will take.
Backtesting In Mt4
Therefore, it helps to start off by testing one input at a time and use larger step intervals. Once you get an idea of what works, you can start to fine tune the settings.
After you get results that you like, be sure to do one last test with the normal Strategy Tester settings to make sure that all of your new settings work well together.
Where to Get MT4 EAs
There are many places that you can get MT4 EAs.
You can start by taking a look at the MetaTrader EA repository. This will give you a good idea of what is out there.
However, youâll quickly see that there are a ton of EAs, but you donât know how most of them trade. If you donât know how they work, how will you know when they stop working?
Therefore, the best thing to do is to learn a trading strategy, test it, then create your own EA.
Even if you donât know how to program in MT4, you can always find a programmer to create an EA for you.
Iâve used several programmers over the years and they were able to create exactly what I wanted.
To see the programmers I use, go here.
The Difference Between .MQ4 and .EX4 Files
You may notice that there are two different types of EA files. This section will explain the difference.
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 .mq4 file) is not very efficient in terms of processing speed, so itâs converted into a version that the computer can use efficiently (the .ex4 file).
These files are also known by the following names:
- .ex4 = compiled, program or executable file
- .mq4 = source code file
When you add a .mq4 file to MT4, it will automatically be converted to a .ex4 file, when you open MetaTrader 4.
If you purchase an EA on the internet, it will usually come in .ex4 format. This is because the .ex4 file hides the developerâs programming and doesnât allow others to copy the code and resell it.
However, if you create an EA yourself, or you work with a programmer to create an EA from scratch, the EA will be in .mq4 format.
One final note on these filesâŚbefore working with a programmer, be sure that they will give you the .mq4 (source code) version. That shouldnât be a problem since youâre paying them.
But double check before you start working with them.
To get help with finding a MetaTrader 4 programmer, I have created this guide and list of programmers.
âŚand no, you cannot use MT4 files with MT5, and vice versa. This is a common question.
A Final Word of Caution
Finding an EA that will make you money while you sleep is a sexy idea. But remember that there are no free lunches in trading.
You can still screw up an EA that has been profitable in backtesting.
Here are a couple of ways that you can do that.
First of all, you have to decide when to turn on your EA.
That may sound obvious, but when an EA hits a losing streak, it can be very tempting to turn it off to stop the bleeding.
âŚand when you turn it off is usually when it starts working againâŚor so it seems.
So remember that you have to understand the statistical characteristics of your EA, so you know when it is doing something thatâs out of the ordinary.
For example, if your backtesting shows that you should only have a maximum of 5 losses in a row, but your EA has currently lost 10 trades in a row, then itâs probably time to turn it off and evaluate whatâs going on.
However, you certainly shouldnât turn it off after 6 losses in a row, no matter how mentally painful that is. Based on your stats, thatâs usually the time when it should start winning again.
Second, many new traders donât test their strategy enough and jump into live trading too quickly.
There are many variables that can affect the performance of an EA in live trading, so be sure to âstress testâ them all before you risk real money. Test it with a wide spread, multiple pairs and use as much historical data as possible. Six months of data is not a valid test.
The more robust your testing, the more likely your EA will work in live trading.
Now get to work testing đ
Related Articles
If youâre into automatic Forex trading via Expert Advisors (EAs), thatâs great! There are some advantages to building EAs to trade, like eliminating human error and being able to run years of backtesting in a couple of hours.
EAs have their limitations though. For instance, choosing good support and resistance levels to take your trading setups from is a pretty subjective process. How are you going to program an EA to only take trades from good support/resistance levels? Sometimes manual backtesting is the way to go.
When it comes to manual backtesting, you have some different options. You can use a backtesting software, like Forex Tester, to help you keep track of your performance, and also to allow you to factor in spread, broker rules, etcâŚ. While that is a great training tool, and a faster process for those who can afford it, today Iâm going to show you how to manually backtest a trading strategy in Metatrader 4 (MT4).
How to Manually Backtest a Trading Strategy in Metatrader 4 (MT4)
If youâre using a new installation of MT4, you may not have enough data to work with on your longer time periods, i.e., Daily, Weekly, and Monthly. If you need more chart history to work with, open your âHistory Centerâ (F2) and download or import the required data for your currency pair.
Note: You can save time and hard drive space by only downloading the data that you need. For instance, if you are only going to be backtesting your trading system on the Daily charts, there is no point in downloading 1 Minute (M1) data.
Next, you need to rewind your chart history in MT4, so make sure the green auto scroll button is not engaged (see the image below). Rewind the chart history by dragging with your mouse or using your â arrow key.
Note: To start manually backtesting, you need to know a few, useful Metatrader 4 hotkeys. Mainly, F12 moves the chart forward by 1 candlestick at a time. To move the chart backward by 1 candlestick at a time, hit Shift+F12.
Once youâve gone backward far enough in your chart history, simply hit F12 until a setup appears that meets the requirements the trading strategy that you are testing. In the example below, I used a morning star candlestick pattern as my entry signal.
When manually backtesting a new trading strategy in MT4, some traders plot out their entry, stop loss, and take profit levels at each trading setup (like I did in the image above). However, this can be tedious â especially if you plan to take a hundred or more backtesting trades.
A faster way to backtest is to skip plotting or measuring anything at all, unless you need to. Stick to your rules. If the price goes straight to your stop loss, then you obviously count that as a loss. If price action goes directly to your take profit, then you count that as a win.
When the trade result is obvious, nothing else needs to be done. When the result is not so obvious, you can simply measure using the crosshair in MT4 (click the mouse wheel or Ctrl+F).
In the image above, you can see the same trade setup as before. This time, I simply measured the pips from my entry to my stop loss, and then doubled that to get my take profit.
In either example, itâs easy to see that my trade did not quite hit a full take profit. However, by only measuring with the crosshair, I was able to determine the result much faster and move on to the next trade.
Putting Your New Manual Backtesting Skills to Good Use
I suggest doing a couple hundred backtesting trades, for each new strategy, using these techniques. Determine your risk and write down the results of each trade, e.g., -2%, +4%, BE, etcâŚ. To get an accurate representation of your trading strategyâs profitability, you need to do the math on a hypothetical trading account as well.
Example: Starting with a hypothetical trading account of $1,000, a 2% loss brings the account to $980. After a 4% gain, the account is up to $1,019.2. The next trade was stopped out at break even (BE), resulting in no change.
Itâs important to track your profit and loss on each currency pair separately, because most trading strategies experience, at least, some variance in performance between pairs. Many perform extremely well on certain pairs and extremely poorly on others.
Some of these techniques may seem obvious to you, but learning how to manually backtest a trading strategy in Metatrader 4 (MT4) can save you a lot of time and money down the road. Although tedious at times, going through these steps, thoroughly, will help you weed out the loosing strategies, and build up your confidence in the winning strategies.