BarsInProgress
Previous Topic  Next Topic 

Definition

An index value of the current Bars object that has called the OnBarUpdate() method. In a multi-bars strategy, the OnBarUpdate() method is called for each Bars object of a strategy. This flexibility allows you to separate trading logic from different bar events. In a single Bars strategy this property will always return an index value of 0 representing the primary Bars and instrument the strategy is running on.


See additional information on running multi-bars strategies.


Property Value

An int value represents the Bars object that is calling the OnBarUpdate() method.


Syntax

BarsInProgress


Examples

// Lets assume this sample strategy was added to a ES 12-06 1 minute chart

protected override void Initialize()
{
    // Add a 5 minute Bars object: BarsInProgress index = 1
    Add(PeriodType.Minute, 5);
}

protected override void OnBarUpdate()
{
    // Check which Bars object is calling the OnBarUpdate() method
    if (BarsInProgress == 0)
    {
        // A value of zero represents the primary Bars which is the ES 12-06
        // 1 minute chart.
        // Do something within the context of the 1 minute Bars here

    }
   else if (BarsInProgress == 1)
    {
        // A value of 1 represents the secondary 5 minute bars added in the Initaliaze()
        // Do something within the context of the 5 minute Bars
    }
}