NinjaScript > Educational Resources > Tips >

Creating User Defined Input Parameters

Print this Topic Previous pageReturn to chapter overviewNext page

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.

1. Open your NinjaScript file

2. 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.

3. Scroll down to the bottom of the editor and expand the minimized “Properties” section by clicking on the + sign on the left.

4. Use the following template code for each parameter you wish to create

[Description("Numbers of bars used for calculations")]


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.

5. Use the "Description" field to provide a brief description of what the parameter does. Use the “GridCategory” field to group similar parameters together

6. Pay attention to this line as the object type will vary depending on the type of parameter you wish to make:

public int Period


7. 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); }


8. 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