Build a level II order book to access bid/ask volume 10 price levels out

Description:
This premium NinjaScript strategy  will create a snapshot of the level 2 book on every OnMarketDepth cycle. This means that at any time you can access the volume of bid/ask orders on the books waiting to be filled 10 price levels out.

This NinjaScript download is a single zip file that you import directly into NinjaTrader. It’s not assembled which means you have full access to view and change the source code either in NinjaScript Editor or your preferred way to edit .cs files.

There are many possibilities with this for automated trading, e.g. enter long when the volume of waiting orders on the bid side outnumber the waiting orders on the ask side. The example image on this page shows the basic data you’ll have access to, and from this information you can explore in countless directions.

Possible use case:
Add this to an existing entry signal as a filter to only enter long when the total bid book volume is 20% greater than the total ask book volume, as this could indicate that the path upward has less resistance than the path downward. This example entry method comes with the code.

Notes:
This code will not work with releases prior to NinjaTrader 8. Click here if you don’t know how to install NT strategies. Use at your own risk, and backtest backtest backtest before you go live with any strategy.

2 comments

  1. Hi
    very interesting work!
    when you add each level volume can you also associate to them a weight inversely proportional to on their distances from the current price ? I saw some examples on TT aADL which were doing that.
    Can you show one or more practical examples on how you can use this data with a NT8 strategy ?
    Thanks

  2. Thanks!
    The weighting would be very easy to do. It would be something like this (you could change the numbers if you don’t want linear weighting):
    (bid volume at position 0) * 1
    (bid volume at position 1) * .9
    (bid volume at position 2) * .8
    (bid volume at position 3) * .7
    etc.

    One practical use would to add this to an existing entry signal of your own as a filter to only enter long when the total bid book volume is double the total ask book volume, as this could indicate that the path upward has less resistance than the path downward.

    I’ll add both of these to the freemium section today.

    EDIT: I’ve added the weighted order book to the freemium section, and the entry filter I mentioned above is now incorporated into the core strategy itself in the premium section.

Leave a Reply

Your email address will not be published. Required fields are marked *