Ticks are required for testing and optimizing Expert Advisors, because they use tick data for operation. Testing can be performed on real ticks provided by a broker or on ticks generated by the strategy and based on minute data.
Testing and optimization on real ticks are as close to real conditions as possible. Instead of generated ticks based on minute data, it is possible to use real ticks accumulated by a broker. These are ticks from exchanges and liquidity providers.
When testing on real ticks, a spread may change within a minute bar, whereas when generating ticks within a minute, a spread fixed in the appropriate bar is used.
If the Market Depth is displayed for a symbol, the bars are built strictly according to the last executed trade price (Last). OnTick event is triggered on all ticks regardless of whether the Last price is present or not.
Please note that trading operations are always performed by Bid and Ask prices even if the chart is built by Last prices. For example, if an Expert Advisor working on bar open prices receives a signal at Last price, it performs a trade at another price (Bid or Ask depending on the direction). If "Every tick" mode is used, the bars are built by Bid prices, while trades are performed by Bid and Ask ones. The Ask price is calculated as Bid + fixed spread of a corresponding minute bar.
If a symbol history has a minute bar with no tick data for it, the tester generates ticks in the "Every tick" mode. This allows testing the EA on a certain period in case a broker's tick data is insufficient. If a symbol history has no minute bar but the appropriate tick data for the minute is present, these ticks are ignored. The minute data is considered more reliable.
Tick data has greater size compared to minute one. Downloading it may take quite a long time during the first test. Downloaded tick data is stored by months in TKC files in \bases\[trade server name]\ticks\[symbol name]\.
The strategy tester generates tick data based on cached one-minute records in the integer format. It means, the tester copies the required history data from the platform and converts them to the integer format to speed up calculations.
The strategy tester provides several tick generation modes. The most accurate "Every tick" mode is described below. |
The tick generation procedure is different for bars with different tick volumes:
Ticks are not generated for bars with the tick volume equal to one, a tick with the value of bar's Close price is written for them:
Also ticks are not generated for bars with two ticks. First a tick with the Open price and then the tick with the Close price are written:
For bars with 3 or more ticks, there are different schemes of tick generation depending on their number.
Four different schemes are possible for bars with three or more ticks:
Progress option |
Image |
|
---|---|---|
The price moves in one direction and returns to the open price level. Thus a bar has only High (the highest price) and Low (the lowest price). |
||
The price moves in one direction and returns, breaking through the open level. In this case the bar also has only High (the highest price) or only Low (the lowest price), but the Open and Close prices are not equal. |
||
The price moves in one direction, but does not reach the Open price while returning back. |
||
The price moves several points in one direction only. In this case the bar does not have High or Low. |
Ticks are generated based on reference points. The number of such points cannot exceed the tick volume, and cannot be larger than 11 (the point of the Open price is not taken into account).
Reference points are divided into three parts: those for forming the opening shadow, the candlestick's range (between its High and Low) and the closing shadow.
Depending on the number of ticks, the following variants of distribution of reference points are possible:
Number of reference points |
Opening shadow |
Candlestick range |
Closing shadow |
---|---|---|---|
11 |
3 |
5 |
3 |
10 |
2 |
6 |
2 |
9 |
2 |
5 |
2 |
8 |
2 |
4 |
2 |
7 |
2 |
3 |
2 |
6 |
1 |
4 |
1 |
5 |
1 |
3 |
1 |
4 |
1 |
2 |
1 |
3 |
1 |
1 |
1 |
|
Reference points are calculated as the number of points from the open price. The ideal distribution of points (3-5-3) is calculated as follows:
Bull Candlestick
Calculation of Points |
Image |
---|---|
|
Bear Candlestick
Calculation of Points |
Image |
---|---|
|
If a candlestick is doji (Close = Open), previous candlesticks are analyzed. If the previous candlestick was rising, this one is considered falling, and vice versa.
If a shadow is generate using three reference points, and integer values of 3/4 and 1/2 of the shadow size are equal (this happens when the difference between the Open and Low or Open and High is not more than 2 points, i.e. distances of price steps forward and backward are equal), then the shadow is generated as follows:
Bull Candlestick
Calculation of Points |
Image |
---|---|
|
Bear Candlestick
Calculation of Points |
Image |
---|---|
|
A closing shadow is generated the same way. |
If a shadow is generated based on two points, the generation is performed as follows:
Bull Candlestick
Calculation of Points |
Image |
---|---|
|
Bear Candlestick
Calculation of Points |
Image |
---|---|
|
A closing shadow is generated the same way. |
The candlestick range is generated by waves in cycles. If Prev = Low (previous price is the Low price), the following cycle is used:
If Prev = High (previous price is the High price), the following cycle is used:
Where:
N1 and N2 are reference points in one cycle;
Prev is the previous price;
Step is the step size. The step is calculated as follows: (H - L - 1)/(Number of cycles) + 1;
Number of cycles is calculated as (Number of reference points in a range + 1)/2.
Intermediate ticks between reference points are generated according to the following rules:
Tick generation modes can be selected in the strategy tester settings window. The following options are available:
In this mode, all ticks are generated — OHLC and intermediate ticks. The procedure of such generation of ticks is described above.
In this mode only OHLC ticks of 1 minute bars are generated. If the tick volume of a candlestick is greater than 4, then only four prices (Open, High, Low and Close) are generated. If the tick volume is less than 4, then the above rules of candlestick formation are applied.
Selecting this mode does not mean that testing or optimization will be performed on the M1 timeframe. For example, if you select the H1 timeframe in the "OHLC of M1" mode, prices will be generated on each 1-minute bar for the Open, High, Low and Close values. In this case, the OnTick() event of the Expert Advisor is executed four times a minute — at opening, closing, high and low of a one-minute bar, although testing is performed on H1. |
In fact, OHLC prices exist in history data. Thus, only the time of arrival of Open, High, Low and Close ticks is generated during testing, while the price values are taken from the history.
In this mode, OHLC prices of bars of the timeframe selected for testing are generated. The Expert Advisor function OnTick() is executed only at the beginning of the bar (at the Open price). Due to this feature, Stop Levels and pending orders may trigger at a price different from the specified one (especially when testing at higher timeframes). But this allows you to quickly run an evaluation test of an Expert Advisor.
The exceptions are periods W1 and MN1, for which bars are generated once a day instead of once a week or a month respectively. |
There are some limitations on the "Open Prices Only" mode:
The mode of every tick generation is the most accurate, but the slowest one. For quick, but rough testing/optimization, use the "Open prices only" mode. |
This mode allows you to use the Strategy Tester for mathematical computations. It does not require and therefore does not load historical data and information about symbols, and it does not generate ticks. In the tested Expert Advisors, only OnInit(), OnTester() and OnDeinit() are called sequentially.
In this mode, the Custom optimization criterion is used. All fields in the tester settings become inactive, except for the optimization mode and Expert Advisor selection.
Mathematical computations are useful for calculating an extremum of a mathematical function, whose value should be returned from OnTester(). Optimization is aimed at finding the highest value of the function. With a large number of combinations of input parameters of a mathematical function, it is recommended to use the "Genetic algorithm". This allows to significantly accelerate the search.