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

onmarketdepth query

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

    onmarketdepth query

    After coding something based on the OnMarketDepth()
    i looked at the samplecodefor level2Book NT8 code ...

    // protect e.Instrument.MarketDepth.Asks and e.Instrument.MarketDepth.Bids against in-flight changes
    lock (e.Instrument.SyncMarketDepth)
    {

    ............. detail
    process Add Remove Update
    }

    is it recommended or necessary to bracket the code in a lock { }

    I am mostly processing the Update Operation -

    it would seem on printing out all the events that the
    Add and Remove are when new rows are added to the level 2 book
    and when a volume changes on an existing row? or is it only for rows added and removed?

    It seems the information i want and to keep track of comes with the Update for the price level in question and whether at the bid or ask.

    Looking at the help page only has a short example of printing the update operation.

    So my question was to gain a little more clarity confirmation on this.

    if orders are pulled from the order book price level on ask or bid side :

    is an event triggered for Remove of the those orders AND an event for an update to that price level for the bid or ask? or will i only get the update event.

    Also i presume there is no way to know if orders on the book are actually filled by market orders vs pulled/removed?

    Similarly if limits are added to the ask or bid at a price level - the Add event is triggered with the volume of contracts : this is in addition to an update for the change to that price level. So in some instances 2 events are triggered -
    the add event and then update event
    the remove event and then the update event ?

    just trying to figure out the sequence for this (if there is a sequence)

    printing out the values helps to see this somewhat and the indicator i have written is working fine but i am just wanting to be thorough on the data i am processing.

    the indicator i am testing has 2 versions one with the lock bracket code and one without ... the outputs do look different .... so without the lock i am missing some synchronicity in the processing and some events are being missed without the lock code in place?

    Any input to the above would be appreciated

    thanks

    #2
    Hello soulfx,

    Thank you for your note.

    The purpose of the lock, is to provide a complete view of the book at that moment and prevent a situation where the list built from the order book contains data from two different moments. Yes it is recommended to catch a complete picture of that exact moment.

    Looking at the SampleLevel2Book you’ll see that the list will be updated for Add, Remove, or an Update. The print statements contained in OnBarUpdate, and when you apply the indicator you’ll see the default is OnPriceChange, so values will be printed on any price change.

    If an order is pulled from the book, Update will be ran for either the bid or ask, based on this statement,

    Code:
    List<LadderRow> rows = (e.MarketDataType == MarketDataType.Ask ? askRows: bidRows);
    You could write a condition to determine if a bid was removed from the order book vs pulled. For example, if a bid was sitting 3 off from best bid, and the price spiked down 4 levels, if volume traded at that price met or exceeded the resting limit bid order, you might assume it was filled. On the flip side if the price did not trade down and the bid was no longer resting, you might assume it was pulled.

    If limits are added to the bid/ask, the Add event is not triggered, the Update is. Add/Remove are ran when a new price is added or removed from the order book.

    See MarketDepth section of our helpguide:


    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Hello thanks for the clarification - i was running some more tests today and continuing to look at the prints. It does seem that Update is indeed what i need. What i noticed is there was a lot of Remove events with 0 volume .... in fact most were 0 so wondering what the value was or if that is just to inform that price level was removed. yet if i observe the prices with the remove print they are not far from the best bid/offer ... from what i understand we get 10 depth above and below last. Will continue to observe and report. But for now i believe the update gives what i need and i can explore the idea you suggested for determining pulledvsfilled - but i can see that and guage from market orders too perhaps.
      thanks

      Comment


        #4
        I think watching the DOM will reveal when the Remove operation occurs: as the inside market moves, depth at the BBO is removed on one side in favor of depth on the other side as transactions gobble up the resting orders. At the outer edges of the available depth (±10 ticks), I believe that depth volume is also removed to maintain the BBO ±10 ticks range.

        The Add operation occurs when there was no volume at a particular price level, but now there is.

        You may need to consider resting order size that just sits there unchanged. Such will not be available in any of the three operations, neither Remove, Add, nor Update.

        Last edited by tradesmart; 02-13-2017, 02:00 PM.

        Comment


          #5
          Thanks, that makes sense - the the BBO ±10 ticks range aspect was clear ; on closer inspection
          as market orders consume limits and BBO at ask/bid shifts to next level that makes sense and why the Remove volume is 0 - i feel i have more holistic view now in terms of the Operations in the event loop and how they translate/relate to the dynamics of the DOM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          40 views
          0 likes
          Last Post jeronymite  
          Started by bill2023, Today, 08:51 AM
          2 responses
          15 views
          0 likes
          Last Post bill2023  
          Started by sidlercom80, 10-28-2023, 08:49 AM
          167 responses
          2,260 views
          0 likes
          Last Post jeronymite  
          Started by warreng86, 11-10-2020, 02:04 PM
          7 responses
          1,362 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by Perr0Grande, Today, 08:16 PM
          0 responses
          5 views
          0 likes
          Last Post Perr0Grande  
          Working...
          X