An object from the TTickHistory class holds the set number of objects from the TTick class (each object from the TTick class represents an individual tick in the chart).
The strategy will start working only after the specified number of ticks is preloaded (as they are required for data analysis and/or indicators). In the example above we indicated that the strategy uses 100 ticks.
As new ticks appear, the tick history will expand and hold the additional values. Due to this it is sometimes difficult to determine the exact number of ticks in the chart. In order to obtain this information, the Count method (of the TTickHistory objects) is used.
Example:
a:=History.Count; |
As a result, the variable a will hold the number of ticks of the chart history.
There are 3 methods of the TTickHistory objects to access individual ticks. We can index the ticks either from the oldest tick that we use in the chart going forward, or from the most recent (current) one going backwards.
1) The Last() method
When using the Last() method, the index goes from the most recent tick. You can refer to the current tick as to Last(0), to the previous one as to Last(1), etc.
Here is an example of using this method:
a:=History.Last(3).Rate; |
You can also refer to the current (the Last(0)) tick, as to Last.
Example:
a:=History.Last.Rate; |
The example below illustrates an alternative way to access individual ticks.
var a:double; T:TTick;
---------------------
T:=History.Last(3); a:=T.Rate; |
2) The Get() method
When you are using the Get() method, the numeration goes from the beginning of the chart history. The first tick is the tick number 0, the second one is the tick number 1, etc. As a result, the last tick is the tick number 199. Here is an example of using this method:
a:=History.Get(5).Rate; |
It is obvious that the Last method is more convenient when you want to refer to the most recent ticks, and the Get method is more convenient when you want to refer to the oldest ticks.
Nevertheless, you can use any of the two methods to refer to any tick in the chart. You can combine the Last() or the Get() method with the Count method. For instance,
History.Last(0) = History.Get(History.Count-1)
History.Last(1) = History.Get(History.Count-2)
...
and vice versa,
History.Get(0) = History.Last(History.Count-1)
History.Get(1) = History.Last(History.Count-2)