I have a strategy that adds one custom indicator. In that strategy, I access the data series of my indicator via the indicators public property called DataSeries. The trouble is, when I try to access the current value of the indicator, sometimes it returns 0. I highly suspect that this is a multi-threading issue or an event timing issue and that my strategy is accessing the indicator property before it is set internally by the indicator. Here is my pseudo code:
// My Indicator Pseudo-Code:
// ---------------------------------------
public Series<double> DataSeries { get { return Values[0]; } private set { Values[0] = value; } } // Property I am accessing from My Strategy.
protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
{
DataSeries[0] = Close[0];
// DEBUG
if (DataSeries[0] < 1)
{
; // *Breakpoint* [B]never[/B] gets triggered.
}
}
// My Strategy Pseudo-Code:
// ---------------------------------------
private MyIndicator _indicator = MyIndicator(); // This is actually properly instantiated when State == DataLoaded
protected override void OnBarUpdate()
{
double y2 = _indicator.DataSeries[2]; // This value is always correct.
double y1 = _indicator.DataSeries[1]; // This value is always correct.
double y0 = _indicator.DataSeries[0]; // This value is sometimes 0.
// DEBUG:
if (y1 < 1 || y0 < 1)
{
; // *Breakpoint* gets triggered and I can see that y0 is [B]indeed[/B] 0.
}
}
Your help is highly appreciated.

Comment