MarketDepth only updating for the past
MarketDepth only updating for the past
25 Mar 2014, 00:38
I am trying to write an indicator to show the average spread for a bar. Based on the comments I saw in cAlgo.API when I was de-compiling it I think that this should do the trick, but the problem is that I only seem to get values _after_ have put the indicator on a trend, scrolling back in time yeilds no values in MarketDepth.
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class Spread : Indicator
{
[Output("Average Spread Per Bar", PlotType = PlotType.Histogram, Color = Colors.White)]
public IndicatorDataSeries Result { get; set; }
private int m_LastProcessedIndex = 0;
public override void Calculate(int index)
{
var marketDepth = MarketData.GetMarketDepth(Symbol);
List<double> entries = new List<double>();
if (marketDepth.AskEntries.Count > 0)
{
for (int i = m_LastProcessedIndex; i < marketDepth.AskEntries.Count; i++)
{
m_LastProcessedIndex++;
double ask = marketDepth.AskEntries[i].Price;
double bid = marketDepth.BidEntries[i].Price;
double spread = ask - bid;
entries.Add(spread);
}
}
if (entries.Count > 0)
{
Result[index] = entries.Average();
}
}
}
Any ideas?
avinar
25 Mar 2014, 00:43
The title should have been "MarketDepth not updating for the past" - that's what I get for posting before my morning coffee.
@avinar