Four Simple Steps to Backtest and Optimize Your EA on MetaTrader 5
Learn how to backtest and optimize your Expert Advisor in 4 easy steps.
Learn how to backtest and optimize your Expert Advisor in 4 easy steps.
You’ve got an algorithm. You think it’s going to be great. Now you’re thinking to yourself, “Let’s test it out!”
I couldn’t agree more!
One the best features about MetaTrader 5 is it’s built in backtester — and it’s super simple to use!
In this article, I’ll show you how.
In this series, I cover everything you need to build your own advanced Expert Advisor from scratch. I cover:
All of the code that I use is available on my public GitHub repo, and each episode contains working code snippets you can immediately use in your own trading bot.
If you’d like some more general help, join our Discord server here, and if you prefer content in a video format, you can check out my YouTube channel here.
You can find all the code for this series on my GitHub
In this article, I show you how to use the built in back tester from MetaTrader 5.
Before showing you how to use the MT5 back tester, I want to clarify a couple of points that often cause confusion.
It’s worth stating this clearly: Backtesting does not guarantee future results, and neither does a thorough optimization process.
Instead, backtesting is just a simple way of getting a higher level of confidence about your Expert Advisor.
What would it take for Crypto, AI, and Cyber to truly change the world?
No spam. Unsubscribe anytime.
Let’s get into backtesting!
You can find the strategy tester in View -> Strategy tester
In the Settings tab of the Strategy Tester, you can set up your test in whatever way suits you. I’ve listed out each item below for you:
rsi_trading_bot_tutorial
Go ahead and select what you’d like to choose now.
If you’re following along this series, for now, choose the following values:
rsi_trading_bot_tutorial.ex5
XAUUSD
, Timeframe. M1
Last year
No
Zero latency, ideal execution
Every tick
100000
(because why not. Lol), USD
1:200
Fast Genetic Based Algorithm
, set to Balance Max
Optimization in MT5 is primarily handled through the Inputs
tab in your Strategy Tester
. However, before I get into that, I’ll quickly explain your optimization options from the previous step.
Put simply, once you get into optimization, it’s quite common to have literally tens or hundreds of thousands of different possible combinations to test. This can put enormous strain on your compute and time resource, so MT5 offers you a few choices to help you navigate the task:
Ok, back into the actual terminal.
We’ll be optimizing all of our parameters execept for Lot Size. Watch the counter for the number of tests to see how the quantity of tests can quickly skyrocket! I’ll track mine as I update them here.
If I was to use the ‘Slow complete algorithm’, my MT5 estimated that this would take80-83 hours!!!
83 hours to backtest!!!
In contrast, if I was to use the Fast Genetic based algorithm
, this goes down to around 42 minutes.
Note. For reference, this was a 13th Gen Intel(R) Core(TM) i5–13600K 3.50 GHz with 64Gb Ram.
Anyways, run your optimization and let me know how it goes.
Once you’ve run your backtest with optimization, you can check out your results.
To do this, head to the Optimize Results
tab, and start looking around.
For instance, using my test, I was able to see that the best result I had over a year was -$720.14
. Pretty annoying.
Each result will has the parameters listed out for you.
Congratulations on getting your backtest done. I’d be super interested in hearing what results you got for your algorithm, so drop them in the comments!
You might be wondering:
Ok, how do we start levelling up this Expert Advisor on MT5? Check out my next article to learn how!
List of Articles in this Series
My name is James, and you’ll often see me online using the AppnologyJames handle. Although my background and training is in Cyber Security, I’ve spent the last few years building trading algorithms for clients, along with a powerful market analysis platform called TradeOxy.
I love hearing from my readers and viewers, so feel free to reach out and connect with me: