Default Indicator Options with NinjaScript
We’ve put together a series of posts to help you in your journey to learn how to program from scratch, or edit existing NinjaTrader indicators and strategies. All of our posts are geared toward the non-programmer, so even though we will present a lot of information, for all of you more technical people out there, we will not go into all the technicalities of C#, NinjaTrader, or NinjaScript. It’s also important to note that even though we show you how to do something in NinjaTrader, that is by no way the only way to do it. We will present what has worked best for us and what will be most easily understood by someone learning how to program. Finally, for the more advance users, we are going to leave things out and over simplify certain parts because we are focused on learning what we need to so we can get started on our NinjaScript journey.
One of the first things you should do when creating a new indicator is define the default settings. It is important to note that not all default settings need to be explicitly set because they have default values, as outlined below. However, sometimes it is easier to define all the default settings explicitly, even though it is slightly more efficient to let a default setting take on a default value, if that’s the value we would like to use. Often times, we do things while programming that make it easier to read / understand code, like explicitly setting default setting values. This will also ensure our indicator default values are setup correctly (if you have a hard time remembering what the default values are).
Default Settings Basics
The best way to learn each setting is to have a good understanding of each variable and then continue to use them, frequently, to reinforce their behavior. We have compiled a list of the the most frequently used settings, which was compiled from: https://ninjatrader.com/support/helpGuides/nt8/en-us:
- Name: Determines the listed name of the NinjaScript object. When you add an indicator to a chart, this is the name the indicator.
- Description: Text which is used on the UI’s information box to be displayed to a user when configuration a NinjaScript object.
- IsOverlay: If set to true, the indicator plot(s) are drawn on the chart panel. Default set to false.
- IsAutoScale: If set to true, the drawing tool plot(s) are included in the y-scale. Default set to false.
- DisplayInDataBox: Determines if plot(s) display in the chart data box. Default set to true.
- DrawOnPricePanel: Determines the chart panel the draw objects renders. If true, draw objects will appear on the panel where your chart bars are, if set to false, draw objects will appear on the indicator panel. Default set to true.
- BarsRequiredToPlot: The number of bars on a chart required before the script plots. OnBarUpdate will always start calculating for the first bar on the chart (CurrentBar 0).
- DrawHorizontalGridLines: Plots horizontal grid lines on the indicator panel. The indicator panel’s parent chart has a similar option ‘Grid line – horizontal which if Visible property set to false, will override the indicator’s local setting if true. Default set to true.
- DrawVerticalGridLines: Plots vertical grid lines on the indicator panel. The indicator panel’s parent chart has a similar option ‘Grid line – vertical which if Visible property set to false, will override the indicator’s local setting if true. Default set to true.
- PaintPriceMarkers: If true, any indicator plot values display price markers in the y-axis. Default set to true.
- ShowTransparentPlotsInDataBox: Determines if plot(s) values which are set to a Transparent brush display in the chart data box. The default behavior is to hide any plots which have been configured as a Transparent brush, however this behavior can be changed by setting ShowTransparentPlotsInDataBox to true on the indicator. Default set to false.
- ScaleJustification: Indicates the location of the chart scale relative to the chart control. A ScaleJustification enum. Possible values are: Right, Left, or Overlay.
- IsChartOnly: If true, any indicator will be only available for charting usage – indicators with this property enabled would for example not be expected to show if called in a SuperDOM or MarketAnalyzer window. Default set to false.
- Calculate: Determines how often OnBarUpdate() is called for each bar. OnBarClose means once at the close of the bar. OnEachTick means on every single tick. OnPriceChange means once for each price change. If there were two ticks in a row with the same price, the second tick would not trigger OnBarUpdate(). This can improve performance if calculations are only needed when new values are possible. Default value is set to Calculate.OnBarClose.
- IsSuspendedWhileInactive: Prevents real-time market data events from being raised while the indicator’s hosting feature is in a state that would be considered suspended and not in immediate use by a user. Enabling this property in your indicator helps save CPU cycles while the hosting feature is suspended and not in use by a user. Once the hosting feature is in a state that would no longer be considered suspended, the historical OnBarUpdate() events will be replayed allowing the indicator to catch up to current real-time values. Since events in OnBarUpdate() will not be processed while the indicator is suspended, internal NinjaScript functions such as Alert(), PlaySound(), Share(), Print(), etc – or any other method that would be used to notify a user of activity will NOT be processed until the indicator is un-suspended. Default set to false. This property is overridden to “true” automatically by the NinjaScript Code Wizard.
- MaximumBarsLookBack: Determines memory performance of custom Series objects (such as Series, Series, etc.). When using MaximumBarsLookBack.TwoHundredFiftySix, only the last 256 values of the series object will be stored in memory and be accessible for reference. This results in significant memory savings when using multiple series objects. In the rare case should you need older values you can use MaximumBarsLookBack.Infinite to allow full access of the series. A MaximumBarsLookBack.TwoHundredFiftySix series works as a circular ring buffer, which will “loop” when the series reaches full capacity. Specifically, once there are 256 entries in the series, new data added to the series overwrite the oldest data.
Default Settings Examples
As part of this example, we will override DisplayName. DisplayName is the text displayed on the chart panel, where the default value is the NinjaScript type Name along with its input and data series parameters. I like to keep DisplayName clean, so I am going to show you how to do that, along with keeping track of indicator versions:
It’s As Simple As That
Defining and understanding the basic default settings is as simple as that, but now it’s time to build our first complete indicator–checkout Part 6 – First Indicator: CurrentBar.