NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Educational Resources > Tips

Tips Official NinjaScript tips and tricks

Reply
 
Thread Tools Display Modes
Old 02-23-2008, 05:02 AM   #1
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default Creating User Defined Input Parameters

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
    Code:
    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
    Code:
    [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.
  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:
    Code:
    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
    Code:
    set { period = value; }
    Note: If you wish to set an upper bound use Math.Min()
    Code:
    set { period = Math.Min(25, value); }
  8. 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
NinjaTrader_Josh is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Josh for this post:
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating parameters for user input NinjaTrader_Josh Indicator Development 13 08-12-2010 02:47 AM
NYSE-TRIN as user defined input alfie Strategy Development 4 10-30-2007 04:44 PM
user defined class? Folls Strategy Development 4 10-16-2007 06:33 PM
Indicator: Creating a user-defined parameter type (enum) NinjaTrader_Josh Reference Samples 0 09-24-2007 09:12 PM
Maximum number of user defined inputs Folls Indicator Development 1 05-03-2007 07:58 AM


All times are GMT -6. The time now is 09:19 PM.