MarketDepth only updating for the past

Created at 25 Mar 2014, 00:38
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
AV

avinar

Joined 25.03.2014

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
Replies

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

Spotware
26 Mar 2014, 10:38

cAlgo.API doesn't provide access to the historical market depths.

You can retrieve only current snapshot of the market depth.


@Spotware