NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 05-30-2012, 11:43 AM   #1
jbesada
Member
 
Join Date: May 2012
Posts: 73
Thanks: 3
Thanked 0 times in 0 posts
Default Built a coherent Order Book

Hello,

I am using OnMarketDepth event to build a coherent Order Book. I am using the SampleMarketDepth template.
My question is related to have coherent data in a particular Time.
In order to have a coherent OrderBook several instructions need to be processed (for example a change on a price level needs a Remove instruction and an Insert instruction). If in the meantime of these instructions, I perform some calculations they would be wrong because they must be done after the second instruction.
I know it is because race conditions but I wonder if there is any way to know if in a particular time data is coherent.
Related to this problem, I want to know, what is the purpose of MarketDepth member of MarketDepthEventArgs class? It seems to have MarketDepthRowCollection items. Is it up to date? Is it valid? Can I use them to have a coherent real time Order Book?

Thank you in advance
jbesada is offline  
Reply With Quote
Old 05-30-2012, 12:46 PM   #2
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

Hello jbesada,
If you look into the SampleMarketDepth code, it uses the lock statement to make sure the collection is not modified until we finish the processing (of our custom calculation). Please refer here to know more about the lock statement http://msdn.microsoft.com/en-us/library/c5kehkcz.aspx

This is however more of a C# query and beyond what we could support.

The MarketDepth object further exposes the various objects and collections of the level 2 data.

Yes, it is realtime and updated on each change in the order book.
NinjaTrader_Joydeep is offline  
Reply With Quote
Old 05-30-2012, 01:41 PM   #3
jbesada
Member
 
Join Date: May 2012
Posts: 73
Thanks: 3
Thanked 0 times in 0 posts
Default

Thank you for the answer but unfortunately it was not my question.
I know how to use lock and event conditions.
Sorry if my explanation is not very clear.
If for example a change on a price level arises, several OnMarketDepth events need to be processed in an atomic way (lets to say a remove and then an insert for example), but because you don't know how many events are needed, you can have a non coherent Order Book in the meantime of these events (a lock statement doesn't prevent this).
To summarize, changes in the Order Book could need several events to be processed, is there any way to know how many events will come up to have a 'coherent' order book?

Regards
jbesada is offline  
Reply With Quote
Old 05-31-2012, 07:45 AM   #4
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

Hello jbesada,
OnMarketDepth is called and guaranteed to be in the correct sequence for every change in level II. However we have no way to know what data is coming. It is chaotic as it would and orders can get added/updated/deleted at any time.

To know when it is coherent, one needs to have a reference point and also one needs to define what is "coherent".

I look forward to assisting you further.
NinjaTrader_Joydeep is offline  
Reply With Quote
Reply

Tags
level ii, order book

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
built-in order safeguards boaza Automated Trading 9 12-20-2011 02:05 PM
ATM versus Built in order management cashinvestor Strategy Development 5 09-06-2011 09:34 PM
Is the order book misleading? tradingGary SuperDOM and other Order Entry Windows 1 05-06-2010 06:47 PM
How many lines in the book order? pierrreg Charting 9 11-03-2009 10:27 AM
NinjaTrader not realeasing IB order book requests. CraigC Automated Trading 1 07-01-2008 11:10 PM


All times are GMT -6. The time now is 01:42 PM.