usingSystem;usingSystem.Text;usingcAlgo.API;namespacecAlgo.Indicators{[Indicator]publicclassMarketDepthIndicator:Indicator{privateMarketDepth_marketDepth;publicoverridevoidCalculate(intindex){}protectedoverridevoidInitialize(){// Get Market Depth_marketDepth=MarketData.GetMarketDepth(Symbol);// subscribe to event Updated_marketDepth.Updated+=MarketDepthUpdated;}voidMarketDepthUpdated(){// Draw Market Depth Entries in the indicator panelvarse=newStringBuilder();se.Append("Bid");se.Append(" ");se.Append("Ask");ChartObjects.DrawText("DOM",se.ToString(),StaticPosition.TopLeft,Colors.White);se.Clear();se.AppendLine();se.AppendLine();foreach(varentryin_marketDepth.BidEntries){doubledVolume=Math.Round(entry.Volume/1000000.0,2);stringvolume=string.Format("{0}{1}",dVolume,"m");doubleentryPrice=entry.Price;stringaskText=string.Format("{0} {1}",entryPrice.ToString("0.00000"),volume);se.AppendLine(askText);}ChartObjects.DrawText("Bid",se.ToString(),StaticPosition.TopLeft,Colors.Red);se.Clear();se.AppendLine();se.AppendLine();foreach(varentryin_marketDepth.AskEntries){doubledVolume=Math.Round(entry.Volume/1000000.0,2);stringvolume=string.Format("{0}{1}",dVolume,"m");doubleentryPrice=entry.Price;se.Append(" ");stringbidText=string.Format("{0} {1}",entryPrice.ToString("0.00000"),volume);se.AppendLine(bidText);}ChartObjects.DrawText("Ask",se.ToString(),StaticPosition.TopLeft,Colors.Turquoise);}}}
MarketDepth_marketDepth;protectedoverridevoidInitialize(){_marketDepth=MarketData.GetMarketDepth(Symbol);// subscribe to event Updated_marketDepth.Updated+=MarketDepthUpdated;}// user defined function MarketDepthUpdatedvoidMarketDepthUpdated(){// Do something}