BarsArray

View as Markdown

Definition

An array holding Bars objects that are added via the AddDataSeries() method. BarsArray can be used as input for indicator methods. This property is of primary value when working with multi-time frame or multi-instrument scripts.

Property Value

An array of Bars objects.

This property should NOT be accessed within the OnStateChange() method before the State has reached State.DataLoaded

Syntax

BarsArray[int index]

Examples

1protected override void OnStateChange()
2{
3 if (State == State.SetDefaults)
4 {
5 Name = "Examples Indicator";
6 }
7 else if (State == State.Configure)
8 {
9 // Add a 5 minute Bars object which is added to the BarArray
10 // which will take index 1 since the primary Bars object of the strategy
11 // will be index 0
12 AddDataSeries(BarsPeriodType.Minute, 5);
13 }
14}
15
16protected override void OnBarUpdate()
17{
18 // Ignore bar update events for the supplementary Bars object added above
19 if (BarsInProgress == 1)
20 return;
21
22 // Pass in a Bars object as input for the simple moving average method
23 // Evaluates if the 20 SMA of the primary Bars is greater than
24 // the 20 SMA of the secondary Bars added above
25 if (SMA(20)[0] > SMA(BarsArray[1], 20)[0])
26 EnterLong();
27}