NinjaScriptPropertyAttribute

View as Markdown

Definition

Determines if the following declared property should be included in the NinjaScript object’s constructor as a parameter. This is useful if you plan on calling a NinjaScript object from another (e.g., calling a custom indicator from a strategy) or customizing the display parameter data on a grid or from a chart. This also used to make parameters optimizable in the Strategy Analyzer.

Warning: Only types which can be Xml Serialized should be marked as a NinjaScriptAttribute, otherwise you may run into errors when persisting values in various scenarios (e.g., saving workspace, or running Strategy Optimizations). Should you have a property you wish to use as user defined input, you will need to implement a secondary simple type (such as an int or string) as the value to be serialized as user input. Please see the example below which demonstrates using a simple type as the NinjaScriptProperty against types which cannot be serialized.

Syntax

[NinjaScriptProperty]

Parameters

This object contains no parameters.

Examples

Basic usage of NinjaScriptProperty

1#region Properties
2// set **NinjaScriptProperty** to ensure this property is used when calling from another object
3[NinjaScriptProperty]
4public bool MyBool
5{ get; set; }
6
7// do not set **NinjaScriptProperty** since this property is not required to call
8
9// nor do we wish to display it on the chart label
10
11public int MyInt
12
13{ get; set; }
14
15//#endregion

Using a simple type as the NinjaScriptProperty against types which cannot be serialized

1[NinjaScriptProperty]
2[XmlIgnore] // cannot serialize type of **TimeSpan**, use the **BeginTimeSpanSerialize** object to persist properties
3public TimeSpan BeginTimeSpan
4{ get; set; }
5
6// users will configure this "string" as the TimeSpan which will be set as a TimeSpan object used in data processing
7
8[Browsable(false)] // prevents this property from showing up on the UI
9
10[Display(Name = "Begin TimeSpan", GroupName = "NinjaScriptStrategyParameters", Order = 1)]
11
12public string BeginTimeSpanSerialize
13
14{
15
16 get { return BeginTimeSpan.ToString(); }
17
18 set { BeginTimeSpan = TimeSpan.Parse(value); }
19}