PositionsAccount

View as Markdown

Definition

Holds an array of PositionAccount objects that represent positions managed by the strategy’s account. This property should only be used when your strategy is executing orders against multiple instruments.

Index value is based on the array of Bars objects added via the AddDataSeries() method. For example:

First Bars is ES 1 Minute
Secondary Bars is ES 5 Minute
Third Bars is NQ 5 Minute

PositionsAccount[0] == ES position
PositionsAccount[1] == Always a flat position, ES position will always be PositionsAccount[0]
PositionsAccount[2] == NQ position

Tips:

  • For single instrument scripts, please see PositionAccount object
  • For Strategy Positions, please see Positions

Property Value

An array of PositionAccount objects.

Syntax

PositionsAccount[int index]

Examples

1protected override void OnStateChange()
2{
3 if (State == State.SetDefaults)
4 {
5 Name = "ExampleStrategy";
6
7 }
8
9 else if (State == State.Configure)
10 {
11 AddDataSeries("ES 03-15", BarsPeriodType.Minute, 5);
12 AddDataSeries("NQ 03-15", BarsPeriodType.Minute, 5);
13 }
14}
15
16protected override void OnBarUpdate()
17{
18 Print("ES account position is " + PositionsAccount[0].MarketPosition);
19 Print("NQ account position is " + PositionsAccount[2].MarketPosition);
20
21 // Alternative approach. By checking what Bars object is calling the OnBarUpdate()
22 // method, we can just use the Position property since its pointing to the correct
23 // position.
24 if (BarsInProgress == 0)
25 Print("ES account position is " + PositionAccount.MarketPosition);
26 else if (BarsInProgress == 2)
27 Print("NQ account position is " + PositionAccount.MarketPosition);
28}