Developing Indicators
<< Click to Display Table of Contents >> Developing Indicators |
Indicators are the building blocks of any automated trading system. NinjaScript allows you to develop custom indicators quickly. 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 and across indicators
Custom indicator development follows a logical progression.
The OnStateChange() 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.
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.
The NinjaScript Editor will perform both syntax and semantic checks and list any errors at the bottom of the window. If there are logic problems with your indicator, they will be listed in the Log tab of the NinjaScript 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 NinjaScript Output window.
Once the coding effort is completed, you must then compile the indicator (several second process) directly from the NinjaScript Editor.
The completed indicator is now available through any window that can use an indicator, such as a Chart.
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 Indicator Series 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 |