Strategy Testing And Optimization On MetaTrader 4

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.

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.

Comments are closed.