• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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, 09: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, 09: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, 09: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 pjsmith, 04-14-2018, 06:14 AM
                3 responses
                480 views
                0 likes
                Last Post NinjaTrader_EricB  
                Started by losfer, Today, 05:29 AM
                1 response
                4 views
                0 likes
                Last Post NinjaTrader_EricB  
                Started by otislauwaert, Today, 04:36 AM
                0 responses
                6 views
                0 likes
                Last Post otislauwaert  
                Started by Tiang, Yesterday, 11:33 PM
                0 responses
                5 views
                0 likes
                Last Post Tiang
                by Tiang
                 
                Started by MakesTrades23, Yesterday, 07:51 PM
                1 response
                17 views
                0 likes
                Last Post NinjaTrader_AlanP  
                Working...
                X