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");Chart.DrawStaticText("DOM",se.ToString(),VerticalAlignment.Center,HorizontalAlignment.Center,Color.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);}Chart.DrawStaticText("Bid",se.ToString(),VerticalAlignment.Center,HorizontalAlignment.Center,Color.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);}Chart.DrawStaticText("Ask",se.ToString(),VerticalAlignment.Center,HorizontalAlignment.Center,Color.Turquoise);}}}
usingcAlgo.API;usingcAlgo.API.Internals;namespacecAlgo{// This sample shows how to get a symbol market depth and use it[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]publicclassMarketDepthSample:Indicator{privateint_askNo;privateint_bidNo;privateMarketDepth_marketDepth;[Output("Bid Entries", LineColor = "Red", PlotType = PlotType.Histogram, Thickness = 5)]publicIndicatorDataSeriesBidResult{get;set;}[Output("Ask Entries", LineColor = "Blue", PlotType = PlotType.Histogram, Thickness = 5)]publicIndicatorDataSeriesAskResult{get;set;}protectedoverridevoidInitialize(){_marketDepth=MarketData.GetMarketDepth(SymbolName);_marketDepth.Updated+=MarketDepth_Updated;;}privatevoidMarketDepth_Updated(){_askNo=0;_bidNo=0;varindex=Bars.ClosePrices.Count-1;for(vari=0;i<_marketDepth.AskEntries.Count;i++)AskResult[index-i]=double.NaN;foreach(varentryin_marketDepth.AskEntries){AskResult[index-_askNo]=(-1)*entry.VolumeInUnits;_askNo++;}for(vari=0;i<_marketDepth.BidEntries.Count;i++)BidResult[index-i]=double.NaN;foreach(varentryin_marketDepth.BidEntries){BidResult[index-_bidNo]=entry.VolumeInUnits;_bidNo++;}}publicoverridevoidCalculate(intindex){}}}
1 2 3 4 5 6 7 8 9101112131415161718192021222324
importclrclr.AddReference("cAlgo.API")fromcAlgo.APIimport*importmathclassTest():definitialize(self):# Get Market Depthself.marketDepth=api.MarketData.GetMarketDepth(api.Symbol)# Subscribe to event Updatedself.marketDepth.Updated+=self.on_market_depth_updateddefon_market_depth_updated(self):# Draw Market Depth Entries in the indicator paneldom="Bid Ask"api.Chart.DrawStaticText("DOM",dom,VerticalAlignment.Center,HorizontalAlignment.Center,Color.White)bids="\n\n"forentryinself.marketDepth.BidEntries:volume=round(entry.Volume/1000000.0,2)bids=f"{bids}\n{entry.Price}{volume}m"api.Chart.DrawStaticText("Bid",bids,VerticalAlignment.Center,HorizontalAlignment.Center,Color.Red)asks="\n\n"forentryinself.marketDepth.AskEntries:volume=round(entry.Volume/1000000.0,2)asks=f"{asks}\n{entry.Price}{volume}m"api.Chart.DrawStaticText("Ask",asks,VerticalAlignment.Center,HorizontalAlignment.Center,Color.Turquoise)
1 2 3 4 5 6 7 8 910111213141516171819202122232425
importclrclr.AddReference("cAlgo.API")fromcAlgo.APIimport*importmathclassTest():definitialize(self):# Get Market Depthself.marketDepth=api.MarketData.GetMarketDepth(api.Symbol)# Subscribe to event Updatedself.marketDepth.Updated+=self.on_market_depth_updateddefon_market_depth_updated(self):index=api.Bars.ClosePrices.Count-1# AskResult and BidResult are line outputs of type histogram defined in C# file of indicator foriinrange(self.marketDepth.AskEntries.Count):api.AskResult[index-i]=float('nan')askNo=0forentryinself.marketDepth.AskEntries:api.AskResult[index-askNo]=(-1)*entry.VolumeaskNo+=1foriinrange(self.marketDepth.BidEntries.Count):api.BidResult[index-i]=float('nan')bidNo=0forentryinself.marketDepth.BidEntries:api.BidResult[index-bidNo]=entry.VolumebidNo+=1
MarketDepth_marketDepth;protectedoverridevoidInitialize(){_marketDepth=MarketData.GetMarketDepth(Symbol);// subscribe to event Updated_marketDepth.Updated+=MarketDepthUpdated;}// user defined function MarketDepthUpdatedvoidMarketDepthUpdated(){// Do something}
12345678
definitialize(self):# Get Market Depthself.marketDepth=api.MarketData.GetMarketDepth(api.Symbol)# Subscribe to event Updatedself.marketDepth.Updated+=self.on_market_depth_updateddefon_market_depth_updated(self):# Do somethingpass