A Couple of Simple Custom Indicators for NinjaTrader 8 (NinjaScript)
In this tutorial we will go over creating a Volume-Weighted Average Price (VWAP) indicator and two different variations of a Net Change indicator.
This post will cover a couple of simple NinjaScript indicators created using NinjaScript. I consider these indicators simple because the calculations used for them aren’t incredibly complex. Of course, they could evolve into more complex indicators, but at the core they are relatively simple. This is also the first post that I am making for paid subscribers. The reason for this is that I intend on continuously working on these indicators as I go on, implementing new features as I learn about them.
If you haven’t setup your environment for being able to code and debug NinjaScript files you can view the Trade Testing Environment article. Be sure to continuously check out the House Keeping post for updates as well. It is designed to help make navigation around the Substack easier and to keep you informed about what is going on with HGT and the logic behind it. Paid subscribers will have access to this code (and more) on the HGT private GitHub repository. Code will always be updated first on the GitHub before articles get updated and not all the code in the GitHub has an associated tutorial.
Disclaimer: the following post is an organized representation of my research and project notes. It doesn’t represent any type of advice, financial or otherwise. Its purpose is to be informative and educational.
Volume-Weighted Average Price Indicator
The VWAP indicator was the first NinjaScript indicator that I tried my hand at, and as such, it is a work in progress. In its current state, it calculates everything with a period of zero (0) and cumulates volume data at the beginning of the trade session. There will be some code inside of this indicator acting as a placeholder for improvements down the road.
I only attempted this indicator because the NinjaTrader 8 platform does not come with a VWAP indicator out of the box. Instead, you have to purchase it through one of their upgrade packages. Considering this indicator is often used in day trading, some people might find it helpful. After searching through the NinjaTrader forums, I found some VWAP indicators from the community that were created for NT7. Along with another post from TradingView, I was able to hack together a working (but needs improvement) VWAP indicator.
Calculations For VWAP
According to the aforementioned post, there are five steps in calculating VWAP:
Calculate the Typical Price for the period.
[(High + Low + Close)/3)]
In NinjaScript we can easily access this with built in functions to obtain those exact values.
Multiply the Typical Price by the period Volume.
(Typical Price x Volume)
Volume is accessed with VOL()[0], where the [0] will represent the bar period you are looking at.
Create a Cumulative Total of Typical Price.
Cumulative(Typical Price x Volume)
We will assign this to a variable.
Create a Cumulative Total of Volume.
Cumulative(Volume)
We will assign this to a variable.
Divide the Cumulative Totals.
VWAP = Cumulative(Typical Price x Volume) / Cumulative(Volume)
Calculation taken from the TradingView built in VWAP indicator.1