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

Limited DOM Rows

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

    Limited DOM Rows

    Hi,

    to make it it easy I took a code snippet of a reference sample which builds a list of market depth and populates or updates that list.

    protected override void OnMarketDepth(MarketDepthEventArgs e)
    {
    lock (e.Instrument.SyncMarketDepth)
    {
    List<LadderRow> rows = (e.MarketDataType == MarketDataType.Ask ? askRows: bidRows);
    LadderRow row = new LadderRow { MarketMaker = e.MarketMaker, Price = e.Price, Volume = e.Volume };

    if (e.Operation == Operation.Add || (e.Operation == Operation.Update && (rows.Count == 0 || rows.Count <= e.Position)))
    {
    if (rows.Count <= e.Position)
    rows.Add(row);
    else
    rows.Insert(e.Position, row);
    }
    else if (e.Operation == Operation.Remove && rows.Count >= e.Position)
    {
    rows.RemoveAt(e.Position);
    }
    else if (e.Operation == Operation.Update)
    {
    if (rows[e.Position] == null)
    {
    rows[e.Position] = row;
    }
    else
    {
    rows[e.Position].Price = e.Price;
    rows[e.Position].Volume = e.Volume;
    }
    }
    }
    }

    Question is:

    How can I modify the above or a overall comparable code to only store and or update a limited amount of depth rows e.g. 10 bid and ask depth rows.

    I tried different ways, but cannot get the desired outcome.

    Regards and thanks in advance.
    Last edited by keepsimple; 12-22-2017, 10:30 AM.

    #2
    Hello,

    Thank you for the post.

    In this situation, the number of rows would be controlled by the data provider being used. I could not suggest any ways to increase the number of rows. To limit the number of rows to 10, you would need to use logic.

    Are you trying to only store the first 5 rows of the ask and bid or reset the collection at a specific time?

    Please let me know if I may be of further assistance.
    Last edited by NinjaTrader_Jesse; 12-22-2017, 10:40 AM.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse,

      I want to have an updating window of e.g. 10 levels of bids and offers as displayed in the superdom. in crude for example the code stores way more levels, so have can I limit that to 10.
      Last edited by keepsimple; 12-22-2017, 10:43 AM.

      Comment


        #4
        Hello,

        Thank you for the reply.

        Yes, Are you trying to only store the first 5 rows of the ask and bid or reset the collection at a specific time?

        Please let me know if I may be of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hi Jesse,

          I want to have an updating window of e.g. 10 levels of bids and offers as displayed in the superdom. in crude for example the code stores way more levels, so how can I limit that to 10.

          Comment


            #6
            Hello,

            If you are going to iterate through the list yourself, you could just use a for loop with 10:

            Code:
            for(int i = 0; i < 10; i++)
            {
                LadderRow row = rows[i];
            }
            If you want the list to only contain 10 total elements, you would need to modify the logic that fills the list to stop once a count of 10 is reached.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              is it possible to use something like this in an indicator? Found this in the addon section.

              private void OnMarketDepth(object sender, MarketDepthEventArgs e)
              {


              for (int i = 0; i < marketDepth.Asks.Count; i++)
              {

              }
              }


              Loop through 10 Levels and copy them into the list?

              Comment


                #8
                Hello,

                The private void specifically could not be used in an Indicator.

                The private void you have shown is part of a greater sample for Addons specifically where you subscribe to the market data events from an instrument picker. This process is not needed in an indicator because an indicator already has the override which references the series the indicator is interested in:

                Code:
                protected override void OnMarketDepth(MarketDepthEventArgs e)
                {
                
                }
                In the sample you originally posted, to limit the items in the lists in the or limit how many are displayed, you would either need to only add the number of items you want to each list or iterate over each list the number of elements you want.

                The ask and bid rows are added to the two lists: askRows: bidRows.

                To find 10 ask rows, you could loop over the collection 10 times:

                Code:
                for(int i = 0; i < 10; i++)
                {
                    LadderRow row = askRows[i];
                }

                The sample you had originally posted about would be the suggested way to retrieve and build the rows of market depth from an indicator. You can expand off of that example in any way you wish, but that would be the correct way to build the rows. How you later access the rows in those lists would be up to you.


                Please let me know if I may be of additional assistance.
                JesseNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Radano, 06-10-2021, 01:40 AM
                20 responses
                615 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by Mizzouman1, Today, 07:35 AM
                0 responses
                4 views
                0 likes
                Last Post Mizzouman1  
                Started by i019945nj, 12-14-2023, 06:41 AM
                6 responses
                66 views
                0 likes
                Last Post i019945nj  
                Started by aa731, Today, 02:54 AM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by BarzTrading, Today, 07:25 AM
                0 responses
                3 views
                0 likes
                Last Post BarzTrading  
                Working...
                X