NexusFi: Find Your Edge


Home Menu

 





OnMarketDepth event handler question


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Jasonnator with 2 posts (4 thanks)
    2. looks_two vaibhavkamble with 2 posts (0 thanks)
    3. looks_3 bobwest with 1 posts (1 thanks)
    4. looks_4 iantg with 1 posts (3 thanks)
    1. trending_up 1,961 views
    2. thumb_up 8 thanks given
    3. group 5 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread

OnMarketDepth event handler question

  #1 (permalink)
 vaibhavkamble 
Parsippany, NJ, USA
 
Experience: Beginner
Platform: NinjaTrader
Trading: Currency Futures, Futures, Treasuries, Bonds
Posts: 20 since Mar 2019
Thanks Given: 53
Thanks Received: 6

Hello friends,

I am trying to download market depth events through Ninjatrader custom code that calls OnMarketDepth event handler. My intention is to carryout offline research to understand dynamics order book by analyzing Add and Cancel order events. I have come across various posts on this forum that employs OnMarketDepth event handler to get market depth data but I could not find any example where number of cancelled volume is calculated. I tried using Operation.Remove option to look for cancelled order but it looks like this option is meant for situation where entire order book level needs to be removed from market depth.

I would appreciate if someone can help me pointing in right direction.

Thank you,
Vaibhav

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
Exit Strategy
NinjaTrader
Increase in trading performance by 75%
The Elite Circle
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
33 thanks
Tao te Trade: way of the WLD
24 thanks
My NQ Trading Journal
14 thanks
GFIs1 1 DAX trade per day journal
11 thanks
HumbleTraders next chapter
11 thanks
  #2 (permalink)
 
bobwest's Avatar
 bobwest 
Western Florida
Site Moderator
 
Experience: Advanced
Platform: Sierra Chart
Trading: ES, YM
Frequency: Several times daily
Duration: Minutes
Posts: 8,168 since Jan 2013
Thanks Given: 57,433
Thanks Received: 26,276


vaibhavkamble View Post
Hello friends,

I am trying to download market depth events through Ninjatrader custom code that calls OnMarketDepth event handler. My intention is to carryout offline research to understand dynamics order book by analyzing Add and Cancel order events. I have come across various posts on this forum that employs OnMarketDepth event handler to get market depth data but I could not find any example where number of cancelled volume is calculated. I tried using Operation.Remove option to look for cancelled order but it looks like this option is meant for situation where entire order book level needs to be removed from market depth.

I would appreciate if someone can help me pointing in right direction.

Thank you,
Vaibhav

Interesting technical NinjaTrader question. Anyone have any ideas?

Bob.

When one door closes, another opens.
-- Cervantes, Don Quixote
Reply With Quote
Thanked by:
  #3 (permalink)
 
Jasonnator's Avatar
 Jasonnator 
Denver, Colorado United States
 
Experience: Intermediate
Platform: NT8 + Custom
Broker: NT Brokerage, Kinetick, IQFeed, Interactive Brokers
Trading: ES
Posts: 159 since Dec 2014
Thanks Given: 40
Thanks Received: 166


Ok, I will preface this with, it's not easy. I've been working on this very thing for the better part of a year and here's what you have to do.

You have to track your own entire order book. Essentially, what you see with a super Dom, you have to create in code. If you want any sort of reasonable performance, you'll need to use structs instead of classes and be ready to do some unsafe pointer stuff.

You're on the right track with that override event handler and depending on whether you have an add, remove, or update, you'll have to update your order book builder accordingly.

I'd recommend starting with a sorted dictionary to track each feature you're interested in. I'd use the time converted to the tick (long data type) as the key then a list of structs as your value. Since the updates arrive in time order, the sorted dictionary will give you inherently/significantly better lookup performance. I believe it used binary search underneath in combination with calculating lookup hashes for you.

I'm not able to share the code I have unfortunately but hopefully that helps and gets you pointed in the right direction. You may want to look on GitHub for an order book builder to see how people are doing this stuff. That's what I would do if I were starting over from scratch.

Good luck

Jason

Reply With Quote
Thanked by:
  #4 (permalink)
 
Jasonnator's Avatar
 Jasonnator 
Denver, Colorado United States
 
Experience: Intermediate
Platform: NT8 + Custom
Broker: NT Brokerage, Kinetick, IQFeed, Interactive Brokers
Trading: ES
Posts: 159 since Dec 2014
Thanks Given: 40
Thanks Received: 166

The other bit of information I would offer would be to look into the multivariate hawkes-gamma point process. The are some good papers on arxiv showing some very promising results. Just search for those terms and that will get you going.

When I mentioned features, I mean order cancellation, order adds, etc and store those in your fast collection. You'll have to decide what you consider an order book update. If you take any change in volume/price, be prepared to deal with 8GB+ per day session of the ES. Storing is not an issue but you'll need an efficient binary storage format for however you're doing your analytics.

Reply With Quote
Thanked by:
  #5 (permalink)
 iantg 
charlotte nc
 
Experience: Advanced
Platform: My Own System
Broker: Optimus
Trading: Emini (ES, YM, NQ, ect.)
Posts: 408 since Jan 2015
Thanks Given: 90
Thanks Received: 1,148

Hi I did a a whole thread on market microstructures a while back that included some details around this topic. You can find the old thread here.

It's honestly not too hard to code this. Unless you can get MBO data, most volume data comes by aggregate so you have to un-bundle it yourself with the following logic.

1. Create a variable to hold the "Last update" to a given price level. X price Y volume
2. If and when the OnMarketDepth event handler gives a new update to this price level, you compare this to the variable and determine if this new event added volume or removed volume.
3. If the new event added volume, this is easy part, added volume is just added volume. Create a new variable to hold all your added volume and just keep a running total if you like.
4. For price / volume updates that are less than your variable in step 1, they will only be cancels until the price level gets to the top of the book, but once it hits the level 1 feed then they can be either cancels or transactions, so you have to reference either the OnBarUpdate, or OnMarketData to get the actual transactions. Anything that is subtracting that can't be attributed to the transactions will be your cancels.

Check out the model that I built in the thread I referenced. For every price, For both the bid and ask, I collected the following data.

1. Starting volume
2. Added volume
3. Transacted volume
4. Canceled volume
5. Ending volume

I did my model by price level, so it's the most granular that you can get. I did it all with ninjatrader too, so it can be done, and it wasn't too hard. You can probably code it over a weekend.

Best of luck!






vaibhavkamble View Post
Hello friends,

I am trying to download market depth events through Ninjatrader custom code that calls OnMarketDepth event handler. My intention is to carryout offline research to understand dynamics order book by analyzing Add and Cancel order events. I have come across various posts on this forum that employs OnMarketDepth event handler to get market depth data but I could not find any example where number of cancelled volume is calculated. I tried using Operation.Remove option to look for cancelled order but it looks like this option is meant for situation where entire order book level needs to be removed from market depth.

I would appreciate if someone can help me pointing in right direction.

Thank you,
Vaibhav


In the analytical world there is no such thing as art, there is only the science you know and the science you don't know. Characterizing the science you don't know as "art" is a fools game.
Visit my NexusFi Trade Journal Reply With Quote
  #6 (permalink)
 vaibhavkamble 
Parsippany, NJ, USA
 
Experience: Beginner
Platform: NinjaTrader
Trading: Currency Futures, Futures, Treasuries, Bonds
Posts: 20 since Mar 2019
Thanks Given: 53
Thanks Received: 6

Apologies guys for not getting back to you all earlier but I must thank wonderful folks from this equally wonderful forum.

Many thanks @bobwest for creating thread for my question, thanks @iantg and @Jasonnator for your inputs. I am big fan of @iantg's posts and especially his Red Pill post.

I am working for suggestion given by you and if possible I will share by feedback soon.

Started this thread Reply With Quote




Last Updated on September 10, 2020


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts