Walk Forward Pro Setup

Getting your MQL5 EA ready

MT5 (.mq5) Expert Advisor Setup Instructions

These are the instructions for "MT5" EAs. If you have an "MT4" EA, please use the MT4 EA Setup Instructions

In order for Walk Forward Pro to operate, it is necessary to make a few simple additions to your Expert Advisor (EA). Follow the instructions below carefully to ensure that no problems are encountered. We highly recommend that you copy and paste the small pieces of code from the provided code windows in order to avoid typing mistakes.

READ THESE INSTRUCTIONS CAREFULLY AND FOLLOW THEM EXACTLY. DO NOT RUSH.

YOU WILL BE UP AND RUNNING WITH WALK FORWARD PRO MUCH SOONER IF YOU TAKE YOUR TIME NOW :-)

  1. Header Code

    The image below illustrates where this code needs to be placed (just underneath the '#property' section)

    MQL5 Header Code
    MQL5 Header Code

    To ensure that you don't make any mistakes, copy and paste the text from the code section below:

                            
    //##############################################
    //## Walk Forward Pro Import Start (for MQL5) ##
    //##############################################
    
    #property tester_file "Walk Forward Pro\\WFA Control Files\\InitiatedFromWFP.ctl"
    #property tester_file "Walk Forward Pro\\WFA Control Files\\StageIterationDetails.txt"
    #property tester_file "Walk Forward Pro\\WFA Control Files\\OptPassCounter.ctl"
    
    #import "TSMWFP.ex5"
    void WFA_Initialise();
    void WFA_UpdateValues();
    void WFA_PerformCalculations(double &dCustomPerformanceCriterion);
    void WFA_OnTesterInit();
    void WFA_OnTesterDeinit();
    #import
    
    //############################################
    //## Walk Forward Pro Import End (for MQL5) ##
    //############################################
                                
                            
  2. OnInit() Code

    This code should be placed at the beginning of your OnInit() function, before any of your own code, as shown below:

    MQL5 OnInit() Code
    MQL4 OnInit() Code

    Again, you should copy and paste the code from the code section below to ensure that you do not make any mistakes:

                            
    //## Walk Forward Pro OnInit() code start (MQL5) ##
    if(MQLInfoInteger(MQL_TESTER))
    WFA_Initialise();
    //## Walk Forward Pro OnInit() code end (MQL5) ##
                                
                            

    Note that because the WFA_Initialise() function can only ever be called when MetaTrader is runing the EA in the strategy tester (determined by the 'if' statement), these two lines of code can (if you wish) safely be left in the EA while live trading, without any adverse effect.

    IMPORTANT NOTE FOR OLDER EAs: If you are using an older EA (developed in MQL4 prior to Build 600) your initialization function might be called init() instead of OnInit(). If this is the case paste the WFP code into that function instead. Be careful to ensure you NEVER have both init() and OnInit() functions in your EA, as this will cause your EA to malfunction.

  3. OnTick() Code

    This code should be placed at the beginning of your OnTick() function, before any of your own code, as shown below:

    MQL5 OnTick() Code
    MQL5 OnTick() Code

    Again, you should copy and paste the code from the code section below to ensure that you do not make any mistakes.

                            
    //## Walk Forward Pro OnTick() code start (MQL5) ##
    if(MQLInfoInteger(MQL_TESTER))
    WFA_UpdateValues();
    //## Walk Forward Pro OnTick() code end (MQL5) ##
                                
                            

    Note that because the WFA_UpdateValues​() function can only ever be called when MetaTrader is runing the EA in the strategy tester (determined by the 'if' statement), these two lines of code can (if you wish) safely be left in the EA while live trading, without any adverse effect.

    IMPORTANT NOTE FOR OLDER EAs: A small number of our customers were still using a function called start() in their EAs instead of OnTick(). This was the name for the function in MQL4 EAs prior to Build 600 which was released in 2014. Although MetaQuotes recommend changing EAs to use OnTick(), the start() function is still supported for backward compatibility of older EAs. If your EA uses start() you have two options. 1. You can rename start() to OnTick() and place the WFP code as shown above, or 2. Alternatively, you can place the WFP code at the beginning of your existing start() function. Note that you should NEVER have both start() and OnTick() functions in your EA, as this will cause it to malfunction.

  4. OnTester() Code

    This one is slightly more complicated so please read carefully and take care to choose the correct option for your circumstances.

    Firstly, OnTester() functions are optional in EAs, and so your EA might, or might not already have one. This is a function that MetaTrader calls (if it exists) at the very end of a Strategy Tester run. If your EA already has an OnTester() function, you will add the Walk Forward Pro code to that. If it doesn't you will need to create the whole function.

    Secondly, there are two options depending on whether you already use your own 'Custom Performance Criterion' in your EA, or not. If you do already calculate your own Custom Performance Criterion then the good news is that it can be used with Walk Forward Pro (i.e. Walk Forward Pro can use it as the selection metric for optimizations). If you don't already use your own Custom Performance Criterion (and most people don't), then don't worry that's fine - the default value that Walk Forward Pro calculates will be used instead. However, be careful that you copy the correct code into your EA based on whether you do calculate your own Custom Performance Metric or not.

    For those of you that are interested in finding out more about how MetaTrader uses the Custom Performance Criterion, see the MeteQuotes documentation for the OnTester() function at:
      For MT4: https://docs.mql4.com/basis/function/events
      For MT5: https://www.mql5.com/en/docs/basis/function/events

    OnTester() OPTION 1 - When NOT using your own Custom Performance Metric (Most customers use this option)

    ​If not using your own Custom Performance Metric, your OnTester() function should be constructed as follows:

    MQL5 OnTester() Option 1 Code
    MQL5 OnTester() Option 1 Code

    Again, you should copy and paste the code from the code section below to ensure that you do not make any mistakes:

                            
    double OnTester()
    {
        //## Walk Forward Pro OnTester() code start (MQL5)- When NOT calculating your own Custom Performance Criterion ##
        double dCustomPerformanceCriterion = NULL;  //The default Walk Forward Pro Custom Perf Criterion will be used
        WFA_PerformCalculations(dCustomPerformanceCriterion);
    
        return(dCustomPerformanceCriterion);
        //## Walk Forward Pro OnTester() code end (MQL5) - When NOT calculating your own Custom Performance Criterion ##
    }
                                
                            

    Note that because the OnTester() function is only ever called when MetaTrader is running the EA in the Strategy Tester, this code can (if you wish) be safely left in the EA while live trading, without any adverse effects.

    OnTester() OPTION 2 - When calculating your own Custom Performance Criterion

    If you calculate your own Custom Performance Metric, your OnTester() function should be constructed as follows.

    Make sure that after copying and pasting the code you replace...
      [REPLACE_WITH_YOUR_YOUR_OWN_CUSTOM_PERF_CRITERION_DOUBLE_VARIABLE_HERE]
    ...with your own double variable

    MQL5 OnTester() Option 2 Code
    MQL5 OnTester() Option 2 Code

    Again, you should copy and paste the code from the code section below to ensure that you do not make any mistakes.

                            
    double OnTester()
    {
        //IF YOU CALCULATE YOUR OWN CUSTOM PERFORMANCE CRITERION, DO THAT HERE
    
        //## Walk Forward Pro OnTester() code start (MQL5) - When calculating your own Custom Performance Criterion ##
        double dCustomPerformanceCriterion = [REPLACE_WITH_YOUR_YOUR_OWN_CUSTOM_PERF_CRITERION_DOUBLE_VARIABLE_HERE]
        WFA_PerformCalculations(dCustomPerformanceCriterion);
    
        return(dCustomPerformanceCriterion);
        //## Walk Forward Pro OnTester() code end (MQL5) - When calculating your own Custom Performance Criterion ##
    }
                                
                            

    Note that because the OnTester() function is only ever called when MetaTrader is running the Expert in the Strategy Tester, this code can (if you wish) be safely left in the EA while live trading, without any adverse effects.

  5. OnTesterInit() Code

    You've now done the trickiest part. It's easier from here :-)

    The OnTesterInit() function is optional in EAs, and so your EA might, or might not already have one. This is a function that MetaTrader calls (if it exists) right before a full MT5 optimization. If your EA already has an OnTesterInit() function, you will add the Walk Forward Pro code to that. If it doesn't you will need to create the function.

    This code should be placed at the beginning of your OnTesterInit() function, before any of your own code, as shown below:

    MQL5 OnTesterInit() Code
    MQL5 OnTesterInit() Code

    Again, you should copy and paste the code from the code section below to ensure that you do not make any mistakes.

                            
    void OnTesterInit()
    {
        //## Walk Forward Pro OnTesterInit() code start (MQL5) ##
        WFA_OnTesterInit();
        //## Walk Forward Pro OnTesterInit() code end (MQL5) ##
    
        //## YOUR OWN CODE HERE ##
    
        return;
    }
                                
                            
  6. OnTesterDeinit() Code

    The OnTesterDeinit() function is also optional in EAs, and so your EA might, or might not already have one. This is a function that MetaTrader calls (if it exists) right after a full MT5 optimization. If your EA already has an OnTesterDeinit() function, you will add the Walk Forward Pro code to that. If it doesn't you will need to create the function.

    This code should be placed at the beginning of your OnTesterDeinit() function, before any of your own code, as shown below:

    MQL5 OnTesterDeinit() Code
    MQL5 OnTesterDeinit() Code

    Again, you should copy and paste the code from the code section below to ensure that you do not make any mistakes.

                            
    void OnTesterDeinit()
    {
        //## Walk Forward Pro OnTesterDeinit() code start (MQL5) ##
        WFA_OnTesterDeinit();
        //## Walk Forward Pro OnTesterDeinit() code end (MQL5) #
    
        //## YOUR OWN CODE HERE ##
    
        return;
    }
                                
                            
  7. Compile your Expert Advisor

    Important: If you use multiple MetaTrader installations, make sure you copy your compiled .ex4 file to the experts folder of all the MetaTrader instances that you connect to Walk Forward Pro.

That's it! Your Expert Advisor is now ready to be used with Walk Forward Pro

Like what you've read today? Then please consider sharing

Subscribe to our newsletter

By subscribing you are giving your consent to send you emails in accordance with our privacy policy

About Us

We are passionate about algorithmic trading, and about helping other algorithmic traders reach their full potential.

We help traders to develop robust trading systems that deliver results in live accounts.

Contact

Built in Yorkshire, UK
Proudly serving Europe and the World