INSTALLATION, OPTIMIZATION and BACK TESTING EXPERT ADVISORS

Metatrader Expert advisor should has ex4 or mq4 file extenshion. mq4- sourse code, ex4- compiled code. First of all it is necessary to copy this file to the folder experts of working directory. Under a working directory we understand a root directory, in which we installed MetaTrader 4 terminal.





The second step is to restart MetaTrader . After the restart the expert should be added to the list of experts in the window Navigator . It necessary to stress that the colored icon corresponds to mq4 file. If you have an ex4 file only, an icon in the window Navigator will be grey. The same grey color may mean that the errors in a source code appeared.

 

 


In order to check expert errors, you may press F4, the editor of language MQL4 , and then it is necessary to load the source code of expert into the editor. Press F5 in order to compile the expert advisor. In case of success, the sentence '0 errors' will appear in conclusion window. Warnings are not errors and their presence does not hinder the successful compiling.



 
 

  Now MetaTrader identifies our metatrader expert advisor and the source code of forex expert does not contain errors. Next logical step will be to specify working pair and timeframe for the expert. The easiest way to do it is to apply the technology Drag-and-Drop . For this purpose it is necessary to select metatrader expert, press the left mouse button and drag it on the required chart, then release the button. There is another way. After the selection of metatrader expert advisor, press the right mouse button for context menu, then choose from the menu Attach to and chart .

If you made the steps mentioned above correctly, you should see the window of expert settings, where you should let the expert trade.
Do not forget about the button  Expert Advisors , which is located on one of standard tool bars of the terminal. The button must be pressed.


 


In the case of correct execution of all above-described actions, the name of forex expert advisor and smiling face must appear in the right overhead corner of the chart. It means that an expert is installed and ready to work.


 

  An metatrader expert advisor is almost ready to work. Now we can look over or change operating parameters.
Properties of expert are accessible by pressing F7 , or from context menu of active chart.
 
The changed parameters can be saved by pressing the button Save . The button Load serves for the load of the values, which were stored before. A file with the expert parameters has extension set and this file is kept in the directory experts\presets of your terminal. The button Reset restores the values of parameters on those which are prescribed in an expert itself.
 





All important information about expert work or appeared errors is accessible from the log of metatrader expert advisors. This information is duplicated in a log file which is located in the directory experts\logs . The file name coincides with a current date.







QUOTATIONS
Quotations of the various Metatrader brokers have distinctions, therefore it is necessary to make optimization and backtesting of expert advisors on broker quotations, which you plan to work with. We make tests of our Metatrader expert advisors on quotations of broker AlpariUK, as this broker gives minute and daily quotations from 2004 ( http://www.alpari-idc.com/en/dc/databank.html ) So in order to upload quotations in Metatrader
1. Get and save on your computer minute quotations of necessary pair from AlpariUK History Center for MetaTrader 4.
2. Decompress an archive.
3. Open the window Options MetaTrader 4 by pressing Ctrl +O or from menu Tools/Options . On the inset of Charts, set Max. Bars history and Max. bars charts 2100000000


 

4. Open the window History Center Metatrader 4 terminal by pressing  F2 or from menu  Tools/ History Center





5. Choose minute quotations of necessary currency and press Import . Specify a path to the folder with minute quotations (read points 1 and 2) in the opened window and press OK




In order for the quality of modeling (while backtesting) to be 90%, it is necessary to generate quotation m5, m15, m30 from the minute quotations. It is possible to do using indicator Period Converter




 
IMPORTANT! Testing of experts for other brokers is possible on more short time of history, as the brokers do not give the archives of quotations. It is also important to understand that taking advantage of the button download in the window History Center Metatrader 4 you will upload quotations of Metaquotes but not quotation of your broker. Quotations of Metaquotes can substantially differ from quotations of your broker.



OPTIMIZATION OF EXPERT ADVISORS

Let's examine the optimization of expert advisors on the example of advisor upstream EURJPY. We will optimize the size of stop loss and take profit. If you make optimization for Metatrader broker AlpariUK, then the period of optimization will be: start is 07.2004; the end is the current date.
We recommend to conduct optimization not up to the end of period = to the current date, but up to the end of period = current date – N of days N is chosen directly for every expert and depends on how often expert opens and closes orders. More orders are opened by an expert, less is N. The segment of history beginning of the period = (current date – N of days), the end of period = a current date will enable us to do a backtest of advisor on the area of quotations, which did not participate in optimization. So you are doing so called forward test of advisor.

So for the expert optimization, you should:
terminal, you should:
  1. Open the window strategy tester by pressing Ctrl+R or by pressing the right mouse button on graphic arts to which we added adviser and choose strategy tester.



2.In the window strategy tester , open the window expert properties
3. Select optimized parameters ( in our example stop-loss and stop-profit)
4.Enter the initial values of the optimized parameters, step and stop
5.close a window
6.Select Optimization
7.Choose a model for optimization ( a model “ Open prices only (fastest method to analyze the bar just completed)” corresponds to the most advisors, although for greater accuracy it is possible to test on Every tick (based on all available least timeframes) but then time of optimization substantially will be increased.



8.Press start
9. After completion of optimization, open Optimization result and choose parameters considering a highest income and minimum drawdown. (obviously income should be high and drawdown should be less)
 
TESTING OF EXPERT ON HISTORY ( BACK TESTING)
 
  1. Open the window strategy tester by pressing Ctrl+R or by pressing the right mouse button on graphic arts to which we added advisor and choose strategy tester.
  2. Set a testing model. We recommend to use Every tick model.
  3. Set a testing period and press a start.


 del.icio.us  Stumbleupon  Technorati  Digg 

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this entry.
Comments

  • 6/5/2008 7:20 AM Roberto Azank wrote:
    Great help, thanks.
    Note: The sound on the video is not working, and I tried several computers...
    Thanks again.
    Roberto
    Reply to this
  • 11/17/2008 3:12 PM Pawel wrote:
    Very nice and comprehensive work. One remark - on the beginning you mention that ex4 are compiled files and will appear grey (meaning - they won't work) but you do not elaborate on it any more. Maybe it's a bit off topic, but e.g. for me it would be very useful.
    Reply to this
Leave a comment

Submitted comments will be subject to moderation before being displayed.

 Enter the above security code (required)

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.