Buy Sell Order/Transaction Volume

Description:
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.

This premium NinjaScript strategy will return the total volume per bar, split into buy and sell market orders. The buy sell volume indicator included with NT does the same thing with a different approach, but it is not compatible with backtesting in market replay; this version is. I’ve also found the buy sell volume indicator to be inaccurate, e.g. the total buy/sell volume from the indicator doesn’t always the total bar volume on a chart.

Your strategy’s calculate mode must be set to Calculate.OnBarClose. If you want to run your strategy in Calculate.OnEachTick mode and you don’t want to calculate buys and sells for every tick, you can add a second data series to set the time frame you want to use for determining buy sell volume. See this strategy in the free section.

You could also expand the length of the list that stores the volumes from the default 100 (which would represent the last 100 ticks if in Calculate.OnEachTick mode) to however many ticks you like. This is easily controllable in the dashboard region of the code. For instance, if you’re in  Calculate.OnEachTick mode and want the total number of sells over the last 1000 ticks you would set the transactionListLength variable to 1000 and get the total with sellsList.Sum().

A buy is a transaction at the ask price or above. A sell is a transaction at the bid price or below. Basically these are market orders. Since market orders are “active” (i.e. I want to get in the market right now), and limit orders are passive (i.e. I’ll enter the market only at my desired price, and I may or may not get a fill), a large discrepancy between buys and sells can indicate something about market sentiment. The following image is what the code prints out by default as a basic example of how you can handle the buy sell data.

Possible use case:
If you see over the last five 1-minute bars that the total number of buys is 20% greater than the total number of sells, go long. Strengthen this entry signal by combining it with other signals as an entry filter. 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.

Leave a Reply

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