BarsArray
Previous Topic  Next Topic 

Definition
BarsArray is an array holding Bars objects that are added to a strategy via the Add() method. Bars objects can be used as input for indicator methods. This property is of primary value when working with multi-time frame or multi-instrument strategies.


Property Value

An array of Bars objects.


Syntax
BarsArray[int index]


Examples

protected override void Initialize()
{
    // Add a 5 minute Bars object which is added to the BarArray
    // which will take index 1 since the primary Bars object of the strategy
    // will be index 0
    Add(PeriodType.Minute, 5);
}

protected override void OnBarUpdate()
{
    // Ignore bar update events for the supplementary Bars object added above
    if (BarsInProgress == 1)
        return;

    // Pass in a Bars object as input for the simple moving average method
    // Checks if the 20 SMA of the primary Bars is greater than
    // the 20 SMA of the secondary Bars added above
    if (SMA(20)[0] > SMA(BarsArray[1], 20)[0])
        EnterLong();
}