Working with the MetaTrader4 Strategy Tester: Testing the Expert Advisor

Master Class "Working with the MetaTrader4 Strategy Tester" - Part 2

To select a specific testing interval, check the "Use date" checkbox and select the range of test start and end dates. The day selected as the end date is not subject to testing, the test ends with the last tick of the previous day. At that, all open positions will be closed, and we will see the "close at stop" caption in the testing results against such a position.

Let's skip the visualization mode for now, so if the caption "Visualization" is checked, let's remove it.

Next, we choose testing period (from minute to day) in the drop-down list opposite the "Period" caption. Here, I think, no unnecessary explanation is required.

We'll also skip the optimization mode for now, so don't check the box next to "Optimization".

Input parameters for the Expert Advisor

What is needed is to set the values of the input parameters of the Expert Advisor. For that, there is a button "Properties" (see fig. 2). Each EA has its own set of parameters, but most have standard ones: TakeProfit, StopLoss и Lots. This is, respectively, the level of profit and stop in pips, as well as the volume of one position.

Fig.2. Input parameters of the Expert Advisor.
Fig.2. Input parameters of the Expert Advisor.

As you can see, the MACD Sample Expert Advisor has no StopLoss parameter. That is, the expert does not put a stop. Exit from a losing position is done by closing the position from the market using the opposite, but weaker signal of the strategy. The signal "weakness or strength" level is set by the MACDOpenLevel and MACDCloseLevel parameters. This is the absolute value of the main MACD line in points. In other words, a position is opened if the MACD value is modulo greater than 3 points (at the same time, the other conditions for opening should of course be met). The position will be closed if the signal is weaker - more than 2 pips. These variables are introduced to filter the signals of the indicator during a narrow market flat. The TrailingStop parameter sets the level, reminding ForTrader.org magazine, at which the stop will start to follow the price, protecting the profit already gained. And finally, the MATrendPeriod parameter sets the period of the moving average, the values of which also affect position opening. Note that all of these parameters must be set in the "Value" column. The other three columns are used in the optimization mode of the Expert Advisor, which will be considered later. Also, no check marks should be placed to the left of the parameters.

To set the size of the initial deposit during testing, go to the "Testing" tab (see Fig. 3). We select the initial deposit, the currency of the deposit, as well as the type of positions. In general, Expert Advisors can open positions in both directions - up and down (Long&Short). But it is possible to allow only one type of position: only buy (Only Long) or only sell (Only Short).

Fig. 3. Testing" tab in the Expert Advisor properties window.
Fig. 3. Testing" tab in the Expert Advisor properties window.

Other features of the strategy tester and the start of testing

When you click "Symbol Properties", you will see information on the parameters of the currently selected symbol (we chose EURUSD), which are set on the server of the brokerage company and may differ from one broker to another.

Clicking buttons "Open graph" will open a chart with the results of the last test. In the upper left corner will be written the name of the Expert Advisor and the input parameters with which it was tested. On the chart itself red arrows will indicate dealsand green (or blue depending on the settings) - buy trades. Yellow arrows mark exits from positions.

The "Change Expert" button will take us to the Meta Editor and show us the EA code, which we will study later.

The basic parameters of the test are set (first set all the parameters as shown in Figures 1-3), let's proceed directly to the test. For this press "Start.". Wait until the blue progress bar stops near the "Start" button (this should happen almost instantly), and then go to the tab "Report." at the bottom of the strategy tester window (see Fig. 4).

Fig. 4. Strategy Tester Report.
Fig. 4. Strategy Tester Report.

Exploring the test report

For starters, pay attention to item "Errors of schedule mismatch". You will most likely have a non-zero value there. What does it mean? In real-time mode, the terminal updates historical data for all periods simultaneously - from M1 to MN - with the arrival of each new tick. But when the terminal is switched off or connection is disconnected, and then re-entry takes place, only the data for the currently set period are downloaded. The rest can be downloaded incompletely or with errors. For example, the hour candle 12:00 will have High = 1.5212, and the minute candle 12:23 (it belongs to the hour candle 12:00) will have High = 1.5214. As a result, there is a discrepancy in the data, which can lead to errors in testing. Similarly, there can be discrepancies in tick volume (if you put the cursor over a candle, you will see four parameters - Open, High, Low, Close and a fifth one - Volume). The sum of tick volumes of minute candlesticks should be equal to the tick volume of an hour candlestick, to which these 60 minutes belong. And such correspondence should be observed for all periods from bottom to top and from top to bottom. Violation of this correspondence leads to the appearance of mismatch errors.

Other articles of the master class "Working with MetaTrader4 Strategy Tester"

Leave a Reply

Back to top button