Candle objects

An object from the TCandleHistory class holds a number of objects from the TCandle class (each object from the TCandle class represents an individual candle in the chart).

 

The strategy will start working only after the specified number of candles is preloaded (as they are required for data analysis and/or indicators). In the example above we indicated that the strategy  uses 200 candles.

As new candles appear, the chart history will expand and hold the additional values. Due to this it is sometime difficult to determine the exact number of candles in the chart. In order to obtain this information, the Count method (of the TCandleHistory objects) is used .

 

Example:

 

a:=History.Count;

 

As a result, the variable 'a' will hold the number of candles of the chart history.

 

There are 3 methods of the TCandleHistory objects to access individual candles. We can index the candles either from the oldest candle 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 candle. Note that indexing  starts with 0 not 1. You can refer to the current candle 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).Close;

 

ribbonactfx43

 

 

You can also refer to the current (the Last(0)) candle, as to Last.

 

Example:

 

a:=History.Last.Open;

 

The example below illustrates an alternative way to access individual candles.

 

var

a:double;

Cand:TCandle;

 

---------------------

 

Cand:=History.Last(3);

a:=Cand.Close;

 

 

2)The Get() method

 

When you are using the Get() method, the index starts from the oldest candle. Note that indexing  starts with 0 not 1.

You can refer to the oldest candle as to Get(0), to the next one as to Get(1), etc.

 

Example:

 

a:=History.Get(5).Close;

 

ribbonactfx44

 

 

It is obvious that the Last method is more convenient when you want to refer to the most recent candles, and the Get method is more convenient when you want to refer to the oldest candles.

Nevertheless, you can use any of the two methods to refer to any candle 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)