I've created an indicator where the calculations are being done in OnMarketData and the inserted into the indicator array in OnBarUpdate. However it seems data coming into OnMarketData at the begining of the bar is not being updated in OnBarUpdate.
Here is the code snippet:
protected override void OnMarketData(MarketDataEventArgs e)
{
if (e.MarketDataType == MarketDataType.Ask) m_LastAskPrice = e.Price;
else if (e.MarketDataType == MarketDataType.Bid) m_LastBidPrice = e.Price;
else if (e.MarketDataType == MarketDataType.Last)
{
if (m_LastAskPrice <= e.Price) AskVol = e.Volume;
else if (m_LastBidPrice >= e.Price) BidVol = e.Volume;
}
}
protected override void OnBarUpdate()
{
//keep updating currentbar
if (m_ActiveBar == CurrentBar)
{
Ask.Set(AskVol );
Bid.Set(BidVol );
}
//new bar: reset
else
{
Ask.Set(0);
Bid.Set(0);
m_ActiveBar = CurrentBar;
}
}
The output from OnMarketData matches T&S perfectly. The only problem is that some values are not being inserted into the data array.
Is the basic approach correct? Is there a better way to synch OnBarUpdate and OnMarketData?
Please advise. Thanks in advance.
Comment