Advanced Guide To MetaTrader 4 - Strategy Testing And Optimization
  1. Advanced Guide To MetaTrader 4 - Introduction
  2. Advanced Guide To MetaTrader 4 - Automated Trading
  3. Advanced Guide To MetaTrader 4 - Expert Advisors
  4. Advanced Guide To MetaTrader 4 - Custom Indicators
  5. Advanced Guide To MetaTrader 4 - Scripts
  6. Advanced Guide To MetaTrader 4 - Strategy Testing And Optimization

Advanced Guide To MetaTrader 4 - Strategy Testing And Optimization

MT4 enables traders to test Expert Advisors prior to using them in a live market. This allows traders to evaluate the Expert's efficiency and to confirm that it operates as expected.

Tester Window
MT4's "Tester" is a multifunctional window where traders can test trading strategies (objective rules for trade entry, exit and management) and also optimize an Expert's parameters to find the combination of variables that will produce the most favorable results. To open the Tester window:

  • In the Main Menu > View > Strategy Tester; or
  • Press the Strategy Tester button in the Standard Toolbar; or
  • Press CTRL + R on the computer keyboard.
Any of these actions will open the Tester window at the bottom of the MT4 screen, as shown in Figure 21.

Figure 21 - The Tester window appears at the bottom of the MT4 screen.


Initially, only the Settings and Journal tabs are seen in the Tester window. The other tabs will appear as certain actions are taken; for example, the Results tab appears only after an Expert has been tested. The Tester window tabs include:
  • Settings - the settings of the testing and optimization; for example, the time period to be tested.
  • Results - the results of the trade operations performed on historical data by the Expert.
  • Graph - a graphical display of the results.
  • Report - a detailed testing report.
  • Journal - a log where all actions and internal messages of the Expert are recorded.
  • Optimization Results - data regarding every optimization pass, including inputs, profitability and drawdowns.
  • Optimization Graph - the results of the optimization shown in graph form.
Setting up Testing Parameters

To test an Expert Advisor, click on the Settings tab in the Tester window. Here, the trader will have to select the:

  • Expert Advisor - Only compiled Expert Advisors will be available for testing, and these will appear in the drop-down menu next to "Expert Advisor."
  • Expert Properties - Once the Expert has been selected, click on the "Expert properties" button to select parameters for each of the three tabs: Testing, Inputs, and Optimization.
  • Symbol and Period - The symbol is defined in the Symbol field; the timeframe is specified in the "Period" field. If there is no historical data saved for the symbol or period, the Tester will automatically download the last 512 historical bars.
  • Model - One of three methods of historical data modeling can be chosen for testing:
o Open prices only - the fastest method suitable for Expert Advisors that control bar opening.

o Control points - results are considered estimates only.

o Every tick - the most accurate method of modeling. Since this method involves a large amount of tick data, it is typically slow and can bog down the computer's operation.

  • Use Date - The historical price data on which the test will be applied; complete the From and To fields to identify a range.
  • Optimization - Check to enable the Expert parameters optimization mode; if it is disabled, the Expert will be tested but not optimized when the "Start" button is pressed.
  • Open Chart - Opens a new price chart with the symbol selected for testing. The chart will show trade entries and exits, and can be opened only after the Expert has been tested.
  • Modify Expert - Click this to open the MetaEditor and make changes to the code, if desired.
  • Start - Press the "Start" button to being testing or optimization. A progress bar will appear at the bottom of the Tester window, as shown in Figure 22.
Figure 22 -A status bar appears at the bottom of the Tester window.


SEE: Stimulate Your Skills With Simulated Trading

Setting up Optimization
MT4 can automatically create consecutive passes of the same Expert, with different inputs on the same data. Performing this optimization can help traders determine the inputs that have the most favorable results. To set up an optimization, traders must specify which variables will be optimized by clicking on the "Expert properties" button in the Tester window. This opens a new window with three tabs, as shown in Figure 23:
  • Testing - general optimization parameters
  • Inputs - inputs are variables that affect the Expert's operation. Check to include inputs in the optimization; leave unchecked to disregard during optimization. If checked, double-click in each field to specify the values for Start (initial value), Step (change interval) and Stop (final value).
  • Optimization - the tab allows traders to apply limitations during optimization. If any of the conditions is met during a separate pass of the optimization process, the optimization will be interrupted. Check to enable a limit condition, such as Profit Maximum and Consecutive Loss.
Figure 23 - Set the Testing, Inputs and Optimization parameters to perform an optimization.


After making the desired selections, click "OK" to close the window. Be sure the box next to the Optimization field on the Tester window is checked (to enable optimization), and click "Start" to begin the optimization. Optimizations take varying amounts of time depending on the type of data on which the optimization is performed and the complexity of the inputs. In general, multi-variable optimizations - those that test multiple levels of multiple variables - take the longest.

Optimization Results

The Optimization Results tab in the Tester window contains a final report of each pass of the optimization. All data are presented in a table with the following fields, shown in Figure 24:

  • Pass - pass number.
  • Profit - net profit (gross profit minus gross loss).
  • Total Trades - total number of trades generated.
  • Profit Factor - ratio between the total profit and total loss. Values less than one indicate a losing system.
  • Expected Payoff - mathematical expectation of winning.
  • Drawdown $ - maximum drawdown in relation to the initial deposit.
  • Drawdown % - maximum drawdown in terms of percentage.
  • Inputs - dynamic values of inputs during each pass.
Figure 24 - Optimization results by pass; the inputs used to create the results of each pass appear in the Inputs column on the far right.


Click any header (such as Profit) to sort data by that field. Right-click the Optimization Results and select "Save as Report" to save a copy of the results.

SEE: Calculating Profits And Losses Of Your Currency Trades

Conclusion
Automated trading and strategy testing/optimization are advanced features of the MetaTrader 4 platform. Automated trading is popular because it removes some of the emotion from trading, helps traders avoid costly order-entry mistakes, and responds quickly to changing market conditions. The ability to test and optimize a trading idea (Expert Advisor) prior to placing it in a live market with real money is an invaluable step in the development of a profitable trading system.


  1. Advanced Guide To MetaTrader 4 - Introduction
  2. Advanced Guide To MetaTrader 4 - Automated Trading
  3. Advanced Guide To MetaTrader 4 - Expert Advisors
  4. Advanced Guide To MetaTrader 4 - Custom Indicators
  5. Advanced Guide To MetaTrader 4 - Scripts
  6. Advanced Guide To MetaTrader 4 - Strategy Testing And Optimization
RELATED TERMS
  1. Optimization

    In the context of technical analysis, it is the process of adjusting ...
  2. Optimal Capital Structure

    The best debt-to-equity ratio for a firm that maximizes its value. ...
  3. Search Theory

    A study of buyers and sellers who cannot instantly find a commerce ...
  4. Window Of Opportunity

    A window of opportunity is a short time period during which an ...
  5. Law Of Diminishing Marginal Productivity

    An economic principle that states that while increasing one input ...
  6. Expert Network

    A group of professionals who are paid by outsiders for their ...
RELATED FAQS
  1. How was the American Dream impacted by the housing market collapse in 2008?

    Learn how the American Dream was impacted by the housing collapse in 2008. Due to the housing collapse, millions ended up ... Read Answer >>
  2. How can Economic Order Quantity be used to lower inventory costs?

    Learn what economic order quantity is, how it is calculated and how to find the optimal economic order quantity to minimize ... Read Answer >>
  3. How does the law of diminishing returns affect marginal revenue?

    Find out how the economic law of diminishing returns affects a business' marginal revenue, eventually reducing the effectiveness ... Read Answer >>
  4. How do I build a profitable strategy when spotting a Triple Bottom pattern?

    Learn about the triple bottom chart pattern and how to create a profitable trade strategy based on this pattern, including ... Read Answer >>
  5. What trading strategies help investors withstand a drawdown?

    Understand the concept of drawdown and the importance for traders of having a trading strategy that takes temporary drawdown ... Read Answer >>
  6. What is the difference between a drawdown in banking and a drawdown in trading?

    Understand the two completely different meanings of the term ''drawdown'' as it is applied within the contexts of trading ... Read Answer >>
Hot Definitions
  1. Physical Capital

    Physical capital is one of the three main factors of production in economic theory. It consists of manmade goods that assist ...
  2. Reverse Mortgage

    A type of mortgage in which a homeowner can borrow money against the value of his or her home. No repayment of the mortgage ...
  3. Labor Market

    The labor market refers to the supply and demand for labor, in which employees provide the supply and employers the demand. ...
  4. Demand Curve

    The demand curve is a graphical representation of the relationship between the price of a good or service and the quantity ...
  5. Goldilocks Economy

    An economy that is not so hot that it causes inflation, and not so cold that it causes a recession. This term is used to ...
  6. White Squire

    Very similar to a "white knight", but instead of purchasing a majority interest, the squire purchases a lesser interest in ...
Trading Center