I am using series in my strategy (code below) but facing issue when accessing current value of the series. I set the current member value in ExecutionUpate and check the value immediately after setting. However, on next bar update, myDoubleSeries[0] always prints 0. This is driving me nuts. I would really appreciate any help on this.
private Series<double> myDoubleSeries;
protected override void OnStateChange()
{
// defaul state removed for brevity
else if (State == State.DataLoaded)
{
myDoubleSeries = new Series<double>(this);
}
}
protected override void OnExecutionUpdate( Cbi.Execution e, string executionId, double price, int quantity,
Cbi.MarketPosition marketPosition, string orderId, DateTime time )
{
if(some condition)
myDoubleSeries[0] = 1
else
myDoubleSeries[0] = -1
Print ("Series[0] ={0}", myDoubleSeries[0]); //Prints the value correctly
}
protected override void OnBarUpdate()
{
Print(String.Format("myDoubleSeries.Count = {0}",myDoubleSeries.Count)); //Always 0 even though OnExecutionUpdate member was added to the series
Print ("Series[0] ={0}", myDoubleSeries[0]); //This is always 0 even though myDoubleSeries[0] was set to 1 or -1 in OnExecutionUpdate
}

Comment