Attributes

View as Markdown

The following section documents both .NET native and NinjaScript custom attributes which are commonly used to define the behavior of a NinjaScript property or object. The attributes outlined in the section are primarily used to customize how properties display on the UI, but may also control or how the object is compiled and executed at run time.

  1. The .NET Framework supplies many other pre-defined system attributes which can technically be used for custom NinjaScript programming, but are NOT covered in this section and therefore are considered unsupported. 3rd party developers are encourage to explore additional usage, but the resulting behavior CANNOT be guaranteed.
  2. Not all attributes can be applied to all object types. For example, applying an attribute that is defined to target an class will NOT compile should you attempt to apply this attribute to a type of property.

Common Attributes

BrowsableAttributeDetermines if a property should be displays in the NinjaTrader UI’s property grid
CategoryOrderAttributeDetermines the sequence in which a NinjaScript object’s Display.GroupName categories are arranged in relation to other categories in the UI.
DisplayAttributeDetermines how a property is displays on the NinjaTrader UI’s property grid.
NinjaScriptPropertyAttributeDetermines if a property should be included in the NinjaScript object’s constructor as a parameter
RangeAttributeDetermines if the value of a property is valid within a specified range
XmlIgnoreAttributeDetermines if a property participates in the XML serialization routines (saving workspaces or templates)

Applying Attributes

Attributes are applied directly before the property, method, or class, and are identified by wrapping brackets:

1[AnExampleAttribute] // a pseudo-attribute demonstrating how to target an object
2public object AnExampleProperty // the property that is being targeted
3{ get; set; }

Conventionally, the suffix “attribute” is provided to the object’s name to help determine that is an attribute, however C# does not require you to specify the full name of an attribute. For example DisplayAttribute() will compile the same as Display().