Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Level II Values

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Level II Values

    I am looking to grab the Level II data to use in an indicator I am creating. Specifically, I am looking to grab the 5 Ask order rows above the last price and the volume at each price. Same with the Bid side. Below is the simple code I put together to grab the first Bid & Ask row ( I believe...). Now how do I grab the subsequent rows? Do I need to do something like marketDepthUpdate.Volume[1], marketDepthUpdate.Volume[2]...or something similar? There is very limited info on the ninjascript guide for MarketDepthEventArgs​. Thanks

    HTML Code:
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion
    
    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public class MarketDepthTest : Indicator
        {
            
            private double AskPrice1;
            private double AskVolume1;
            
            private double BidPrice1;
            private double BidVolume1;
            
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Enter the description for your new custom Indicator here.";
                    Name                                        = "MarketDepthTest";
                    Calculate                                    = Calculate.OnEachTick;
                    IsOverlay                                    = true;
                    DisplayInDataBox                            = true;
                    DrawOnPricePanel                            = true;
                    DrawHorizontalGridLines                        = true;
                    DrawVerticalGridLines                        = true;
                    PaintPriceMarkers                            = true;
                    ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive                    = true;
                }
                else if (State == State.Configure)
                {
                }
            }
    
            protected override void OnBarUpdate()
            {
                if(CurrentBar < 1)
                    return;
                
                ClearOutputWindow();
                Print("Ask Book");
                Print("Ask Price=" + AskPrice1 + " Volume=" + AskVolume1);
                
                Print("Bid Book");
                Print("Bid Price=" + BidPrice1 + " Volume=" + BidVolume1);
                
            }
            
            protected override void OnMarketDepth(MarketDepthEventArgs marketDepthUpdate)
            {
                 if(marketDepthUpdate.MarketDataType == MarketDataType.Ask)
                {
                    AskPrice1 = marketDepthUpdate.Price;
                    AskVolume1 = marketDepthUpdate.Volume;
                }
                else if(marketDepthUpdate.MarketDataType == MarketDataType.Bid)
                {
                    BidPrice1 = marketDepthUpdate.Price;
                    BidVolume1 = marketDepthUpdate.Volume;
                }
            }
        }
    }
    
    #region NinjaScript generated code. Neither change nor remove.
    
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
        {
            private MarketDepthTest[] cacheMarketDepthTest;
            public MarketDepthTest MarketDepthTest()
            {
                return MarketDepthTest(Input);
            }
    
            public MarketDepthTest MarketDepthTest(ISeries<double> input)
            {
                if (cacheMarketDepthTest != null)
                    for (int idx = 0; idx < cacheMarketDepthTest.Length; idx++)
                        if (cacheMarketDepthTest[idx] != null &&  cacheMarketDepthTest[idx].EqualsInput(input))
                            return cacheMarketDepthTest[idx];
                return CacheIndicator<MarketDepthTest>(new MarketDepthTest(), input, ref cacheMarketDepthTest);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
        public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
        {
            public Indicators.MarketDepthTest MarketDepthTest()
            {
                return indicator.MarketDepthTest(Input);
            }
    
            public Indicators.MarketDepthTest MarketDepthTest(ISeries<double> input )
            {
                return indicator.MarketDepthTest(input);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
        {
            public Indicators.MarketDepthTest MarketDepthTest()
            {
                return indicator.MarketDepthTest(Input);
            }
    
            public Indicators.MarketDepthTest MarketDepthTest(ISeries<double> input )
            {
                return indicator.MarketDepthTest(input);
            }
        }
    }
    
    #endregion
    
    ​

    #2
    Hello algospoke,

    The level 2 data that is being observed by the platform is simply the level 2 events, there is no order book to where you could access prices or volumes at certain levels. To do that you would have to use your own logic which builds the orderbook based on those events. There is a sample in the link below that covers how to do that and access the values.


    Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.

    Comment


      #3
      Jesse,

      Thanks for directing me to the sample. When I change the list length from 10 to 25 in the sample code, it still only prints 10 lines for Bid & Ask (circled in red below). Why is that? When I enable the Order Flow Market Depth Map, it shows the orders sitting at all tick levels (circled in blue below). My goal is to grab that info to use for analysis in my indicator. It seems I am limited to 10 ticks of data whereas the Order Flow Market Depth Map can show way more than that. Why the difference?

      Click image for larger version

Name:	image.png
Views:	145
Size:	53.4 KB
ID:	1340161

      Thanks

      Comment


        #4
        Hello algospoke,

        Most data providers only offer a small amount of rows for level 2 data, usually 5 to 10 rows. The order flow items use tick data to build the display it provides instead of level 2 data.

        Comment


          #5
          Jesse,

          How do I get that tick data that is used to display the Order Flow Market Depth map? I am looking to grab that data that I circled in blue in my last post for analysis in my indicator.

          thanks

          Comment


            #6
            Hello algospoke,

            Your data provider would be where you get tick data. The depth map uses a combination of tick data for historical bars and realtime level 2 data, unfortunately that item is closed source so I couldn't say exactly how it may calculate.

            Comment


              #7
              Jesse,

              Interesting. I am not looking to understand how it is calculated (I understand it is proprietary), I am just looking to grab the info that is displayed on the chart by Market Depth Map indicator and use it for analysis. Is there a way to grab those values without needing access to the source code?

              Thanks

              Comment


                #8
                Hello algospoke,

                That indicator is currently not exposed for NinjaScript use so there would not be a way to get the specific values it produces at this time.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                563 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                329 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                101 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                547 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                548 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X