Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

How to programatically access Level II depth-of-market data...

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

    How to programatically access Level II depth-of-market data...

    Hello awesome NinjaTrader people!

    Is it possible to programmatically access Level II depth-of-market data?

    I would like to create an indicator and strategy that obtains the data in the 'Level II' window in NT8.

    Q1: Are there sample indicators / strategies that show how this is done?
    Q2: Is there a stock indicator that exists that 'flattens' the level II data into one value for buy strength and the other for sell strength?

    Thanks for the awesomeness!

    Jean-Pierre

    #2
    Hello JPPoulin, thank you for your post.

    See this example that implements a SuperDOM type price/volume ladder in a NinjaScript indicator. All of the info on that page is essential for emulating a SuperDOM.

    I do not know of an example that takes this any further, but what you would need to do is manipulate the askRows and bidRows List. If you wanted to compare the buy strength to the sell strength, subtract the ask volume from the bid volume at the respective rows of each list and that would be the delta.

    Kind regards.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Awesome! Looks like what I need to study.

      I'll look into this and report what I find. Thanks!

      Comment


        #4
        I am using the SampleLevel2Book code to get the market depth and I'm trying to add some variable to sum the bids and asks as well as return the prices with max bids and asks. I keep getting the "index is outside the bounds of the array" in the OBU method. What am I missing?

        protected override void OnBarUpdate()
        {
        //When a new bar forms, print the L2 books.
        if (IsFirstTickOfBar)
        {
        ClearOutputWindow();
        // Prints the L2 Ask Book we created. Cycles through the whole List and prints the contained objects.
        Print("Ask Book");
        for (int idx = 0; idx < askRows.Count; idx++)
        Print("Ask Price=" + askRows[idx].Price + " Volume=" + askRows[idx].Volume + " Position=" + idx);

        // Prints the L2 Bid Book we created. Cycles through the whole List and prints the contained objects.
        Print("Bid Book");
        for (int idx = 0; idx < bidRows.Count; idx++)
        Print("Bid Price=" + bidRows[idx].Price + " Volume=" + bidRows[idx].Volume + " Position=" + idx);
        }

        maxbid = bidRows.Max(item=>item.Price);
        maxask = askRows.Max(item=>item.Price);
        sumbids = bidRows.Sum(item => item.Volume);
        sumasks = askRows.Sum(item => item.Volume);
        MAXBid[0] = maxbid > 0 ? maxbid : 0;
        MAXAsk[0] = maxask > 0 ? maxask : 0;
        SUMBids[0] = sumbids > 0 ? sumbids : 0;
        SUMAsks[0] = sumasks > 0 ? sumasks *-1 : 0;

        }​

        Comment


          #5
          Hi Lance, thanks for posting. Please use Visual Studio debugging to find the error. We will not be able to debug snippets of code through the forum.

          https://ninjatrader.com/support/help..._studio_debugg ing.htm

          Kind regards,
          -ChrisL​
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            It won't let me set a breakpoint. Says labels haven't been loaded.

            Comment


              #7
              Hi Lance, a breakpoint is not needed. It should break at the line that is causing the exception once Visual Studio is attached to the NinjaTrader.exe process you run the code that is causing the error.

              Kind regards,
              -ChrisL​
              Chris L.NinjaTrader Customer Service

              Comment


                #8
                Ok thanks. In the meantime, I'm running the SampleLevel2Book script on replay and I changed the condition to print from the SMA crossover to IsFirstTickOfBar. I've noticed that the Position index values on the output for the Bids goes pretty far out (701 for bids, 67 for asks). I thought

                private List<LadderRow> askRows = new List<LadderRow>(10); and
                private List<LadderRow> bidRows = new List<LadderRow>(10);

                would limit the capacity to 10 for each?

                Comment


                  #9
                  Click image for larger version

Name:	image.png
Views:	292
Size:	24.3 KB
ID:	1224889
                  Here's an example.​

                  Comment


                    #10
                    Hi, thanks for the follow up. There is no set limit to the capacity of a List object in C#. 10 is the storage spaces you give it without needing to allocate more memory into the data structure. To have a hard limit on the capacity you would use an Array instead.

                    Kind regards,
                    -ChrisL​
                    Chris L.NinjaTrader Customer Service

                    Comment


                      #11
                      Got it thanks! Would you know how to find the index of the maximum volume from the lists?

                      double maxvol = bidRows.Max(item=>item.Volume);

                      This works on returning the max bid volume. Now how to reference that index and find the corresponding price? LadderRow is a class with 2 fields so how do I find the index for the e.Volume field?

                      Comment


                        #12
                        Hi Lance, thanks for your reply. You will need to create some C# code that can iterate through the list and find the price/volume pair. It can be done with For loops, etc. There are various examples ifyou Google "find an item in a list C#"
                        Chris L.NinjaTrader Customer Service

                        Comment


                          #13
                          Thanks! Is there a way to create a SampleSuperDOMVolumeColumn similar to the way SampleLevel2Book was created? Make it an indicator instead of a SuperDomColumn?

                          Comment


                            #14
                            Hi Lance, there is the SuperDomColumn type scripts. There are a few examples in the platform already under the SuperDomColumns folder. They require you to custom render the graphics into the column section.

                            Kind regards,
                            -ChrisL​
                            Chris L.NinjaTrader Customer Service

                            Comment


                              #15
                              So I can just convert these to indicator scripts instead of SuperDomColumns? I'm looking to use session volume buy/sell orders using lists showing the price, buy volume, and sell volume similar to Level2OrderBook using bid/ask volumes at price. Would it be easier to just use a 1 Day Volumetric Bar series for the session volumes?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by cmtjoancolmenero, Yesterday, 03:58 PM
                              12 responses
                              42 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by FrazMann, Today, 11:21 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post FrazMann  
                              Started by geddyisodin, Yesterday, 05:20 AM
                              8 responses
                              52 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by DayTradingDEMON, Today, 09:28 AM
                              4 responses
                              27 views
                              0 likes
                              Last Post DayTradingDEMON  
                              Started by George21, Today, 10:07 AM
                              1 response
                              22 views
                              0 likes
                              Last Post NinjaTrader_ChristopherJ  
                              Working...
                              X