AddDataSeries(Instrument.MasterInstrument.Name, BarsPeriod.BarsPeriodType, BarsPeriod.Value, MarketDataType.Ask);
public void set()
{
this.open = this.ns.Opens[this.barsIndex][this.barsAgo];
this.high = this.ns.Highs[this.barsIndex][this.barsAgo];
this.low = this.ns.Lows[this.barsIndex][this.barsAgo];
this.close = this.ns.Closes[this.barsIndex][this.barsAgo];
this.dateTime = this.ns.Times[this.barsIndex][this.barsAgo];
}
Within my strategy I have the following method:
private void updateCandles()
{
if (BarsInProgress == 0)
{
this.yesterdaysBidCandle.set();
this.yesterdaysBidCandle.print("Bid");
}
if (BarsInProgress == 1)
{
this.yesterdaysAskCandle.set();
this.yesterdaysAskCandle.print("Ask");
}
}
Bid 10/22/2024 4:38:00 PM open 1.07985, high 1.07985, low 1.07985, close 1.07985
Ask 10/22/2024 4:38:00 PM open 1.07995, high 1.07995, low 1.07995, close 1.07995
Everything is beautiful until I start running in real time and executing my data analysis code that determines when to buy or sell and where to set stops to exit trades. I only process my analysis after BarsInProgress == 1. Most iterations through OnBarUpdate show output like the one above but on occasion I get situations where I see one but not the other bid and ask candles or one won't have the same timestamp as the other. Either situation kills my strategy.
Any idea why this is happening and how I can ensure that I have both Candle objects properly defined with each iteration of OnBarUpdate within the IsFirstTickOfBar iterations before I run my analysis? It's critical I resolve the problem in order to properly run my strategy.

Comment