Friday, January 20, 2012

How To Backtest An Expert Advisor In Metatrader

How To Backtest An Expert Advisor In Metatrader:
Metatrader is one of the forex platforms. Metatrader is one of the forex platforms. You can download and install it from many forex brokers like FXDD, Alpari etc. Most of them provide a demo account. This article is mainly about how to backtest an expert advisor on a metatrader forex platform.
Once you install metatrader, open it. It will be like in the following picture.

Forex Metatrader Platform

Forex Metatrader Platform
Copy the expert advisor files into the required folders as instructed by the expert advisor manual. Generally whenever you buy an forex expert advisor, you will also get a manual that tells you where to copy the expert advisor files. Generally this is the expert folder, you have to copy the files. Suppose you install metatrader application from FXDD, under program files in C drive, the path will be C:\Program Files\FXDD – MetaTrader 4\experts. But you may have to copy some other files into other folders. Go through the manual and copy the files accordingly. Once you copy all the expert advisor files, you have to restart the metatrader application.
After you restart it, you will see the expert advisor under Expert Advisors in navigator window. Like MACD Sample as you see in the following picture.

Forex Metatrader Navigator Window Showing The Expert Advisors

Forex Metatrader Navigator Window Showing The Expert Advisors
Forex Metatrader Navigator Window Showing The Expert Advisors
Now go to “View” in the top navigation bar, open it and click on “Strategy Tester”. You can also use the shortcut key “Ctrl+R”. You will see the strategy tester as shown in the following picture.

Opening The Strategy Tester From View In Forex Metatrader Strategy Tester Window
Opening The Strategy Tester From View In Forex Metatrader Strategy Tester Window
Once click on strategy tester it will display the strategy tester window at the bottom of the metatrader application.
Metatrader Showing Strategy Tester Window
Metatrader Showing Strategy Tester Window
In the Strategy Tester window you will see the following fields and buttons.
Expert Advisor:
This is a dropdown list that shows all the expert advisors that you have installed. Select the expert advisor that you want to backtest. For example select “MACD Sample”.
Symbol:
This is a dropdown list that shows all the currency pairs that are provided by the broker.
Model:
This is a drop down list that contains three values. The following are those values.
  • Every tick: If you select this value and start backtesting, it will start testing the currency pair you selected by every tick. A tick a the movement of price from one price to another price. Lets say for some currency pair the price has moved from 1.4354 to 1.4355, this is one tick. An hourly char contains many ticks. This is the slow process of back testing.
  • Control points: I don’t really understand how it works. So you can try on web to see how this mode works.
  • Open prices only: If you select this value and start backtesting, it will start testing testing based on the open prices of the candlesticks or bars for that particular time frame you select. Lets say you want to test it on hourly chart, it will test it by the open prices of the hourly candlesticks or bars. So it will move the graph and by the hourly candlesticks or bars instead of ticks in the candlestick or bar.
Use date:
This is a check box and if you select it you can use the from and to dates. Lets say you want to backtest your expert advisor, from Jan 1st, 2001 to Dec 31st, 2001. If you have the history data for that particular year, you can enter the dates in the from and to dates and you can test your expert advisor for that particular year. If you don’t have the history data for that particular year, you need to download it first and then you can start your back testing.
Visual Mode:
If you select this checkbox and start testing, a graph for that particular currency pair will open and you can see the graph moving and you can see the orders that are opening and closing. If you select the checkbox, it will also enable a movable bar using which you can control the speed of the testing. If you move the bar to right while you are testing, it will increase the speed of the backtesting and you will see the currency chart moving at a faster speed. If you move the bar to left while you are testing, it will slow down the testing and you will see the currency chart moving at a lower speed. If you select eh visual mode check box, it will also enable enable a play button using which you can pause the testing. It will also enable a “Skip to” button, using which you can skip the testing to any date which you can select it using a drop down list after that. Generally after you start back testing your expert advisor it will take a lot of time to complete that. You can click on “Skip to” button to complete your testing immediately and you can verify your results.
Expert Properties:
This is a button after the expert advisor drop down list. If you click it will open the expert advisors properties window through which you can set different properties. For example you can select the initial deposit like $5000 or $10000 etc. You can select you want to trade only long positions or only short positions or both. These are the kind of properties that you can select.
Period:
This is drop down list through which you can select the time frame you want test. Let say you want test the expert advisor on the hourly time frame you can select “H1″. If you want to test it on 30 Mins. charts, you can select M30.
Symbol Properties:
This will show you the properties of that particular symbol like the spread etc. Optimization and Open chart: I really don’t understand these two things. But I think you don’t need them when you want to back test an expert advisor.
Modify Expert:
When you click this it will open an editor which is called MetaEditor. It will show the code which you can modify if you know the mql4 programming which is used to program expert advisors.
Once you select visual mode check box don’t select Optimization check box as it won’t open the chart. If you want to see the chart running when you backtest your expert advisor don’t select both optimization and visual mode. Select only visual mode check box.
You will see four more tabs at the bottom of the strategy tester. These are Results, Graph, Report and Journal.

Strategy Tester Window Showing The Different Options

Strategy Tester Window Showing The Different Options
Results:
While the test is running you can see the results like opening orders, closing orders etc. Once the test is completed you can see all the orders that were opened and closed.
Graph:
This will plot the graph between the number of orders and the amount. If the graph is rising throughout the testing that means its a good expert advisor. Some time you need to set the expert advisor properties correctly to make the expert advisor work properly and you will see the graph rising. Even if you make how many changes and the graph is not rising that means its not a good expert advisor.
Report:
A report will be generated when the test is completed. It will show things like gross profit, gross loss, net profit etc.
Journal:
It will show any text messages set by the developer who developed the expert advisor. It is very helpful for developers for debugging when they are developing the expert advisor.
Finally the following is what you have to do.
Install expert advisor properly.
Open the strategy tester from tools -> strategy tester or click Ctrl+R
Select the expert advisor.
Select the symbol.
Select model.
Check “Use date” check box and enter the from and to dates.
Check “Visual mode” check box.
Set the expert advisor properties using Expert properties button.
Select the time frame from the period drop down list.
Click Start.
You should see the chart open and running and the opening and closing orders.

August 22, 2009 By Raj
http://www.forexbees.com/how-to-backtest-an-expert-advisor-in-metatrader/

No comments:

Post a Comment