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.
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).
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).
Exploring the test report
For starters, pay attention to item "Errors of schedule mismatch". Most likely you will have a non-zero value there. What does it mean? In the real time mode the terminal updates the historical data on all periods simultaneously with every new tick - from M1 to MN. But when the terminal is turned off or the connection is cut, and then it enters again, the data is pumped for the current period only. The rest periods can be loaded incompletely or with errors. For example, the hour candle of 12:00 will have High = 1.5212, while the minute candle of 12:23 (it belongs to the hour candle of 12:00) will have High = 1.5214. This results in the divergence of data, which can lead to errors in testing. Likewise, there can be differences in the tick volume (if you move the cursor over the candlestick, we see four parameters - Open, High, Low, Close, and a fifth to them - Volume). The sum of the tick volumes of one-minute candles should be equal to the tick volume of the one-hour candle, to which these 60 minutes belong. This correspondence should be observed for all periods from the bottom to the top and from the top to the bottom. The violation of this correspondence leads to the appearance of mismatch errors.