You can create user defined input parameters for both NinjaScript Indicators and Strategies. Although user defined input parameters can be specified as part of the initial set up of NinjaScript Indicator or Strategies using the Wizard you may have a requirement to add new parameters at a later point in your development process. To create these parameters you will need to edit your NinjaScript code and follow these steps.
- Open your NinjaScript file
- Expand the minimized “Variables” section of your code and create a private variable for your parameter
Code:private int period = 5;
- Scroll down to the bottom of the editor and expand the minimized “Properties” section by clicking on the + sign on the left.
- Use the following template code for each parameter you wish to create
Code:[Description("Numbers of bars used for calculations")] [GridCategory("Parameters")] public int Period { get { return [COLOR=red]period[/COLOR]; } set { [COLOR=red]period[/COLOR] = Math.Max(1, value); } }
- Use the "Description" field to provide a brief description of what the parameter does. Use the “GridCategory” field to group similar parameters together
- Pay attention to this line as the object type will vary depending on the type of parameter you wish to make:
Code:public [COLOR=red]int[/COLOR] Period
- In the "set" line, simply set it to “value” if you do not wish to create a lower bound for the parameter
Code:set { period = value; }
Code:set { period = Math.Min(25, value); }
- Now, wherever in your code you want to call the user-definable parameter, just use "Period".
Code:if (SMA(Period)[0] > SMA(Period)[1]) // Do something
Comment