Primary Instrument: 'MSFT'
Secondary Instrument: '^SP500'
Period: Daily
BarsBack: 4
Initialize()
{
CalculateOnBarClose = true;
BarsRequired = 0;
Add("^SP500", PeriodType.Day, 1);
Add(StrategyPlot(0));
StrategyPlot(0).PanelUI = 1;
}
To investigate data availability for all instruments for a particular bar I placed this debug code in OnBarUpdate:
OnBarUpdate()
{
string logText = "";
logText += String.Format("BarsInProgress:{0} Instrument:{1} CurrentBar:{2} Date:{3}", BarsInProgress, Instruments[BarsInProgress], CurrentBar, Time[0]);
Log(logText, LogLevel.Information);
}
It produced the following output (from newest to oldest)
BarsInProgress: 1 Instrument:^SP500 CurrentBar:2 Date:6/29/2009
BarsInProgress: 0 Instrument:MSFT CurrentBar:2 Date:6/29/2009
BarsInProgress: 1 Instrument:^SP500 CurrentBar:1 Date:6/26/2009
BarsInProgress: 0 Instrument:MSFT CurrentBar:1 Date:6/26/2009
BarsInProgress: 1 Instrument:^SP500 CurrentBar:0 Date:6/25/2009
BarsInProgress: 0 Instrument:MSFT CurrentBar:0 Date:6/25/2009
Since I want to do a calculation involving values from both DataSeries it seemed I should add the following condition to ensure both DataSeries values for the CurrentBar were available:
OnBarUpdate()
if (BarsInProgress == 1)
{
//do some calculation and assign it to the plot
StrategyPlot(0).Value.Set(Closes[0][0] + Closes[1][0]);
}
However, no plot lines were drawn. If I changed the condition to:
if (BarsInProgress == 0)
the plot worked fine.
1) What's the timing relationship between 'OnBarUpdate' and 'Plot.Value.Set'?
2) What is the best 'BarsInProgress' practice for performance and stability when using multiple instruments in the same timeframe?
Thanks
- Fred

Comment