PDA

View Full Version : Creating User Defined Input Parameters


NinjaTrader_Josh
02-23-2008, 06:02 AM
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
private int period = 5;Note: This is also where you set the default value for your parameter.
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
[Description("Numbers of bars used for calculations")]
[GridCategory("Parameters")]
public int Period
{
get { return period; }
set { period = Math.Max(1, value); }
}Note: In the "get" and "set" lines make sure you use the private variable you created in step 2.
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:
public int Period
In the "set" line, simply set it to “value” if you do not wish to create a lower bound for the parameter
set { period = value; }Note: If you wish to set an upper bound use Math.Min()
set { period = Math.Min(25, value); }
Now, wherever in your code you want to call the user-definable parameter, just use "Period".
if (SMA(Period)[0] > SMA(Period)[1])
// Do something