Download MetaTrader 5

Strategy Tester: Modes of Modeling during Testing

13 September 2005, 13:10
MetaQuotes Software Corp.
7
8 365

Introduction

Many programs of technical analysis allow to test trading strategies on history data. In the most cases, the testing is conducted on already completed data without any attempts to model the trends within a price bar. It can be made quickly, but not precisely enough.

It is important to choose a relevant way of modeling price bars to make a quality testing of a trading strategy. Indeed, there cannot exist an ideal situation when there is a full tick history for an extremely accurate testing. It is very difficult for a normal trader to find the full tick history for a period of several years, in order to analize it.

To solve this problem, the data of more precise periods can be used as reference points with modeling price changes between them.

Ways of Modeling Price Bars

There are three ways of modeling development of bars used in MetaTrader 4 Client Terminal:



  • Every tick (the most precise method based on all available least timeframes)
  • Control points (a very crude method based on the nearest less timeframe)
  • Open prices (quick method on completed bars, only for Expert Advisors that explicitly control bar opening)

Intermediate price bars are generated before testing starts, the results being saved in file (for example: /tester/history/eurusd_1440_1.fxt). Every time the Start button is clicked, Tester will newly generate the file containing the testing sequence of ticks. Fxt-files are easy to open in the terminal as offline charts via File -> Open offline.

The use of data cached before allows to perform tests on the basis of the own intermediate data. To do so, it is sufficient to save file in a proper format (*.FXT format, completely open)into /tester/history/ directory. These files are easy to open in terminal as offline charts through File -> Open offline.



Examples of Modeling

Let us begin with the simplest modeling method based on a one-hour chart. Now, let us study the one-hour bar (September, 5 2007, 10:00) highlighted with red:




Open Price

Some traders do not wish to depend on particularities of intrabar modeling, so they create Expert Advisors trading on the bars already completed. The fact that the current price bar is fully completed can only be known when the next one appears. These are the Expert Advisors, for which the mode of "Open Price" modeling is intended.




In this mode, first, bar is opened (Open = High = Low = Close, Volume=1), and this allows the Expert Advisor to identify the end of completion of the preceding price bar. It is this incipient bar, on which the Expert Advisor's testing is launched. At the next stage, the current bar fully completed is yielded, but no testing is performed on it!

Control Points (the nearest less timeframe)

Method of modeling control points is intended for crude estimate of Expert Advisors trading within a bar. To use this method, historical data of the nearest less timeframe must be available. In the some cases, the data available from a smaller timeframe do not completely cover the time span of the timeframe under test. If there are no data of a smaller timeframe, the bar evolution is generated on basis of predefined wave templates, as it was the case in the preceding third version of MetaTrader 3 Client Terminal.

As soon as historical data of the less timeframe appear, these are these data that are interpolated. However, the really existing OHLC prices of the less timeframe appear as control points. In the most cases, the results of tests of Expert Advisors by method of control points can be considered as estimated results only, not as final ones. Such results are of intermediate, estimated nature. The chart below shows how the on-hour bar of 2007.09.05 10:00 developed by method of control points.




Every Tick (available least timeframes)

This mode allows to model price movement within a bar in the most precise way. Unlike "control points", the every-tick method uses for generation not only data of the nearest smaller timeframe, but also those of all available smaller timeframes. At that, if there are data of more than one timeframe for a certain time span available simultaneously, the data of the smaller timeframe are used for generation. Like the preceding method, this method generates control points based on the OHLC data of the smallest available timeframe. To generate price movements between control points, interpolation based on the predefined templates is used, too, so the availability of one-minute data that cover the entire testing range is extremely desirable. It may happen that several identical ticks are generated one after another. In this case, duplicated quotes are filtered out, and the volume of the last one of such successive quotes is fixed.




A possible large amount of tick data generated must be considered. This may influence consumption of operating system and speed of testing.

Attention: There is no need to launch the every-tick testing if there are no smaller timeframes fully covering the timeframe under test. This modeling is intended only for testing on the basis of data of smaller timeframes!

Using the Range of Dates when Modeling

The range of dates can be used for both Expert Advisor's testing and for generation of testing sequence of bars. There is often no need to generate data of the whole history, especially for Every Tick modeling, where the amount of unused data can be very large. So, if at the initial generation of testing sequence there was a possibility to use the range of dates, then bars exceeding the given range are not generated, but just overwritten in the output sequence. The data are not excluded from the sequence in order to be able to calculate indicators correctly for the whole history obtained. It must be noted that the first 100 bars are not generated either, this limitation does not depend on the set up range of dates.

Referencing M1 Timeframe

To check the accuracy of intrabar modeling, the minutes chart of September, 5 2007, between 10:00 and 11:00 p.m. will be used.




In the every-tick mode, the following sequence was generated:


Since the mean tick volume of each bar within this range does not exceed 5, the sequence was generated with the minimal use of interpolation. Practically all prices are really existing OHLC prices.


Even without scaling, just by simple superimposing of a one-minute chart onto a one-hour chart (close prices are shown as a green line on the one-hour chart generated), they appear as practically identical:



Conclusions

Maximally precise testing can be performed and simulation veracity can be well assured if there are auxiliary smaller timeframes available that 100-% cover the timeframe under test. I.e., the problem of a qualitative every-tick testing turns into the search for detailed historical data...


Translated from Russian by MetaQuotes Software Corp.
Original article: https://www.mql5.com/ru/articles/1511

Last comments | Go to discussion (7)
MetaQuotes Software Corp.
MetaQuotes Software Corp. | 29 Dec 2006 at 12:27
jmiranda:

Once there's no smaller time frames then 1 minute, does the Every Tick method generates prices within an 1 minute bar at a 1 min time frame?

Yes.
MetaQuotes Software Corp.
MetaQuotes Software Corp. | 29 Dec 2006 at 12:28
Paldamo:
Why does the OPEN PRICE ONLY setting, generates orders at time =0 and at time =21:00?
Sorry, for delay. Anyway you should investigate your EA logic.
MQL4 Comments
MQL4 Comments | 15 Jul 2008 at 05:01

dear all,

I tested my EA and my modeling quality is 90% (start from 1st february 2008 till 14th july 2008).

with use trade: "everytick...."

but when I extended the period of testing (older than january 2008),

the modeling quality shown "N/A".

Could anyone explain to me how the MetaTrader calculate the Modeling Quality so the result of modeling quality could change dramatically like the data I shown above??

Many thanks for your help.

Rgds,

Michael

Rahima
Rahima | 27 Aug 2014 at 19:37

Hi,

Since most of the articles regarding testing of trading algos are old I wonder if there is any updates. Particularly I'm interested in finding out if I can download the sample of rearranged (bootstrapped) forex rates to MetaTrader 4 and apply testing on those samples?

Thanks 

kemalturgay
kemalturgay | 7 Oct 2014 at 21:10
I think that this subject needs a more clear explanation ... some parts of the article can not be understood easily.
Step on New Rails: Custom Indicators in MQL5 Step on New Rails: Custom Indicators in MQL5

I will not list all of the new possibilities and features of the new terminal and language. They are numerous, and some novelties are worth the discussion in a separate article. Also there is no code here, written with object-oriented programming, it is a too serous topic to be simply mentioned in a context as additional advantages for developers. In this article we will consider the indicators, their structure, drawing, types and their programming details, as compared to MQL4. I hope that this article will be useful both for beginners and experienced developers, maybe some of them will find something new.

Here Comes the New MetaTrader 5 and MQL5 Here Comes the New MetaTrader 5 and MQL5

This is just a brief review of MetaTrader 5. I can't describe all the system's new features for such a short time period - the testing started on 2009.09.09. This is a symbolical date, and I am sure it will be a lucky number. A few days have passed since I got the beta version of the MetaTrader 5 terminal and MQL5. I haven't managed to try all its features, but I am already impressed.

False trigger protection for Trading Robot False trigger protection for Trading Robot

Profitability of trading systems is defined not only by logic and precision of analyzing the financial instrument dynamics, but also by the quality of the performance algorithm of this logic. False trigger is typical for low quality performance of the main logic of a trading robot. Ways of solving the specified problem are considered in this article.

Using text files for storing input parameters of Expert Advisors, indicators and scripts Using text files for storing input parameters of Expert Advisors, indicators and scripts

The article describes the application of text files for storing dynamic objects, arrays and other variables used as properties of Expert Advisors, indicators and scripts. The files serve as a convenient addition to the functionality of standard tools offered by MQL languages.