Developing Indicators

NinjaScript > Educational Resources >

Developing Indicators

Print this Topic Previous pageReturn to chapter overviewNext page

The building blocks of any automated trading system are indicators. NinjaScript allows you to develop custom indicators in rapid time. A few key points are:

 

Custom indicators are compiled and run natively within the NinjaTrader application providing the highest performance possible
Indicator values are calculated at the current bar which ensures that you do not accidentally include future data in your calculations
You can retain calculations between bar updates
You can retain and share calculation values between bar updates across indicators

 

Custom indicator development follows a logical progression.

 

Wizard
The wizard allows you to define your overall indicator parameters which include name, properties, inputs, plots and oscillator lines. The wizard will then generate the necessary NinjaScript code and open up the NinjaScript Editor.

 

Initialize() Method

The Initialize() method is called once before any initial calculation triggered by an update bar event. This method is used to configure the indicators plots, lines and properties. The wizard will generate the required NinjaScript code for this method for most cases.

 

OnBarUpdate() Method

The OnBarUpdate() method is called with either with each incoming tick or on the close of each bar depending on how you deploy the indicator at run time. Your core indicator calculation logic is contained within this method.

 

Debug

The NinjaScript Editor will perform both syntax and semantic checks and list any errors at the bottom of the NinjaScript Editor. If there are logic problems with your indicator, they will be listed in the Log tab of the NinjaTrader Control Center during run time. You can use the Print() method within your script to help debug your code. Output will be sent to the NinjaTrader Output window.

 

Compilation

Once the coding effort is completed, you must then compile the indicator (several second process) directly from the NinjaScript Editor.

 

Usage

The completed indicator is now available through any window that can use an indicator such as a Chart window.

 

Tutorial Descriptions

All internal NinjaTrader indicators come with full source code and can be viewed within the NinjaScript Editor. Please review the tutorials within this section for detailed walk throughs of custom indicator development.

 

Level 1 - Demonstrating the use of price variables
Level 2 - Demonstrating the use of indicator on indicator
Level 3 - Demonstrating the use of a "for" loop to build a simple moving average indicator
Level 4 - Demonstrating the use of IndicatorSeries objects to retain historical custom calculations data series
Level 5 - Demonstrating the use of custom plot coloring based on threshold values
Level 6 - Demonstrating the use of custom of drawing using bar color, back color and line colors