Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnMarketDepth method

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

    OnMarketDepth method

    Hello,

    I use OnMarketDepth method to build price ladder the same way like it is done for "SampleLevel2Book" Next, price ladder I use to create indicator which shows me some bar values in seperate window. I know that OnMarketDepth is a real-time data stream but is there any way to keep values which I get from price ladder? When I change timeframe all outputs which I collect disapear and my indicator is buit from the beginning based on real-time data stream.

    I would be glad for any help.


    #2
    Hello kanarkia,

    Thank you for the post.

    The script would need to save "slices" of the level 2 data. A good data structure for this would be the Dictionary structure because it takes two types for the key/value. Your key could be a DateTime object and the values could be a level 2 "slice" or image for that time.

    Please let me know if you have any questions.

    Comment


      #3
      Hello,

      It makes sense. Thanks for that. One question more. Is there any method to keep it saved and available always when Ninjatrader starts?

      Comment


        #4
        Hello kanarkia,

        Thanks for the reply.

        There are no methods in NinjaTrader that allow for storing indicator values. One would need to store the data in a text file, XML file, or an SQL DB and retrieve the data when the script starts up.

        Please let me know if I can assist further.

        Comment


          #5
          Hello ChrisL,

          Thanks for the replay.

          Would you suggest the best and the easiest way to do that? Any example which I can relay on?

          Cheers

          kanarkia

          Comment


            #6
            Hello kanarkia,

            Thanks for the reply.

            This project would take some advanced C# concepts such as data organization and serializing a complex data structure to a file for storage. It might even take some Asynchronous programming as to not hang up NinjaTrader's processing.

            I modified the SampleLevel2 book a bit by adding in memory slice storage. As a disclaimer, this sample is not complete and not considering many things such as:

            1. Loading the previously gathered historical data from a txt, JSON, or some other kind of file while in the historical mode.
            2. When/how to write the collected data to a file and clear out the Dictionaries memory.
            3. How often we should gather this data.
            4. Since I was getting duplicate keys for the DateTime key, I needed to append a GUID to each DateTime key to keep them unique, this could lead to us needing to consider how to access the data we need properly, possibly even consider a different key for the structure altogether.

            Please let me know if you have any questions.



            Attached Files

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            647 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            368 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            108 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            571 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            573 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X