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.
If you want to access the current bar’s buy/sell volume, your strategy’s calculate mode must be set to Calculate.OnEachTick. Otherwise, you can only access the current bar’s volume after it closes (at which point it will be 1 bar ago). If you want it both ways, 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.
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.
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.