Today is Thu, September 28, 2017 10:00:38 GMT
RSS Follow Us Follow us on Twitter Friend us on Facebook
MT4 Trading & Education Educational Videos How To Run A Metatrader Backtest

Hi, this is Shaun Overton with and In this ten minute video, I’m going to show you how to setup a backtest for MetaTrader 4. You can follow along using a free OANDA demo account by clicking the link below this video.

Register for a free OANDA MT4 demo account here.

Video Script

Once you’ve opened MetaTrader and decided that you need to run a backtest, the first step is to get historical data. There’s a little bit preloaded data, but it’s not enough to run a very lengthy backtest.

Backtesting is about more than looking at historical performance. You can use your experience with historical data to analyze how an expert advisor performs in different market conditions.

My go to example for is always the moving average cross. The idea is that a fast moving average crosses above a slow moving average, you might consider that a buy signal.

That type of strategy is naturally designed for a trending market. The signals always occur late because it’s based on a lagging indicator. The theory is that trends are potentially large enough that entering after a trend starts and exiting the trade after it finishes should leave room for upside.

That’s the theory. Markets range trade about 70% of the time. If the market isn’t trending and you’re running a trend trading strategy, I can tell you now that your trend trading strategy isn’t likely to do well if no trends appear.

Backtesting offers insights into how your expert advisor behaves when the market doesn’t go your way. It helps you plan for downside scenarios and, if you do it properly, backtesting can aid you with developing realistic performance expectations.

I’m assuming you’ve already installed the expert advisor that you’d like to test. If you haven’t done that, Forex News has another video available showing you how to install the EA.

You need to load data for the currency pair you wish to backtest before you start running tests. It’s exciting to analyze the markets, but the tests are only as good as your data, so don’t jump ahead.

I like gold. That’s the chart I’ve chosen here.

I need to know the time frame and currency pair in order to load the correct data. No matter what you want to do, you should consider loading one minute data. One minute data is the smallest time frame available. By using the most accurate data possible, you improve the accuracy of your backtest.

The whole point in doing this is to give yourself an accurate picture of historical performance. Loading one minute data improves the quality of your backtest to give you a more accurate estimate.

Open a one minute chart for gold, which is the instrument I’m backtesting in this video. Go to the top left menu and select File / New Chart / Gold / XAUUSD.

Now change the time frame. Select the M1 option from this menu strip, or go to Charts / Periodicity / One minute

We need to turn off autoscroll now that the chart is open. Push the button at the top with the little green triangle. It resembles a play button. You can also right click on the chart and click properties, or push F8. Select properties, then Common. Uncheck next to Chart Autoscroll.

Now that the chart is open, go to Tools / Options. Choose the tab labeled “Charts”. Max bars in history, change it to 999999999. Max bars on chart needs to be the same, 99999999999. That settings allows MT4 to load as much historical data as you could possibly want.

Go back to your one minute charts. The next step is pretty boring – you need to push the home key while MT4 downloads your historical data. This part takes quite a long time and unfortunately, it only works if you sit there pushing the home key. If you forget to turn off the autoscroll, the chart jumps to the current bar.

I selected one hour charts for backtesting because I find them to strike the best balance between trading frequency and trading costs. Every time you enter a trade, you pay the broker the spread as a cost of entering. When you trade hyperactively on M1 charts or M5 charts, it’s incredibly difficult to trade with any sort of edge; the costs of trading are simply too prohibitive.

The chart that I’d like to backtest is the one hour chart. So, I need to repeat this process by scrolling back on H1 charts until I’ve loaded enough data to cover the duration of my testing period.

Change to the H1 like this. Confirm that autoscroll is off, and then again push the home key until the dates extend beyond your testing window.

We’ve finished all the leg work. We can skip the data loading step for any future tests involving H1 gold charts. If you decide to test another currency pair or time frame, then you need to follow this data loading process.

Let’s move on to loading our EA in the backtester and choosing our settings. I’m going to use the MACD Sample EA in this video because it appears by default in OANDA’s MetaTrader. I know that everyone watching this has this EA already loaded on their computer.

The work we’ve done so far is for XAUUSD – gold – on one hour charts. Select that option from the drop down menu.

You’re asked to select the model. This relates to how quickly and accurately you want the test to run. Your selections can enormously impact the test results.

Expert advisors run sequentially through time. If you took all price history available throughout the day, which is commonly known as tick data, it would contains tens of thousands of prices every single day.

Condensing that information into blocks of time makes the data far more legible and easier to analyze. The display method can very – candlesticks, bars, lines on the chart. They all represent at least one common element. The start or open price of the time period and the end or close price for the time period. I casually refer to these discrete time elements as bars – you should assume that I mean one hour period of time for this video.

If you have a strategy that runs intrabar, meaning your EA opens trades without waiting for the bar to close, you absolutely must use Every Tick. Otherwise, the backtester is forced to make assumptions about the price’s behavior. This can create severe discrepancies between the modeled performance and what should have happened historically.

Every tick is the most accurate option available, but it’s also the most time consuming. EAs that trade only at the open of a new bar can get away with either using control points, so long as the stop loss and take profit do not face the risk of getting hit within the same bar. If either your stop or take profit can possibly get hit within a single bar, the backtester may confuse which was struck first: the stop or the take profit. This again can create huge discrepancies in the reported results. The backtester might say you won when you lost and vice versa.

All of that is a long way of telling you to use Every Tick unless you have a compelling reason to do otherwise. I don’t recommend running any backtests using Open Only prices. The modelling errors always come out too severely and the test is useful for analysis.

Use data allows you to control the start and end date for the test. The format is year-month-date. The option on the left is the start date. The option on the right is the end date. My test will run from February 1, 2013 to February 1, 2014.

Over here on the right, I can control the chart that I want to look at. Choose H1 as the time frame, which stands for one hour charts.

Underneath that is spread. That too can have a substantial impact on the backtest. The spread is a cost of trading. It’s critical that your backtest use at least the broker’s typical spread or worse.

You want to assume what happens when things go wrong, not what might happen in fairy tale land. Historical backtests are usually the best case scenario – you should generally expect a reduction in performance when you move into the future.

Using a spread that is worse than the broker’s spread is advisable to account for both with variable spreads, and potential negative slippage. The backtest always gives you perfect fills, which I assure you does not happen in the real world. Slippage is a very real and present element of trading.

I’m going to set it to 30 for this backtest, which is 30 micropips or 3 pips. That’s far worse OANDA’s typical spread. If a strategy can survive a 3 pip spread on EURUSD, it can be an encouraging sign of performance potential.

Lastly, we need to go to expert advisor. This is where we control the inputs unique to the expert advisor that you’re testing.Click the inputs tab.

Every EA has different settings. Instead of talking about the MACD Sample EA in detail, I want to keep this high level so you understand the different columns.

Here on the left are the settings used in the backtest. If you want to change the lot size traded for every signal, this is the box that you change.

The boxes on the right only apply to an optimization, which we’ll cover in a separate video.

Push ok when you’re happy with the settings.

Visual mode does not affect the test results. If you want to see trades fire off on the charts, then put a check next to this option. Leave it unchecked if you just care about the performance report.

Pushing start kicks off the backtest and you’re ready to analyze the results.

You can start backtesting your EAs in a free MetaTrader practice account from OANDA. Click the link below this video to open your free demo account.