• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Creating User Defined Input Parameters

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Creating User Defined Input Parameters

    Applies to: NinjaTrader 7

    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
    Last edited by NinjaTrader_Jesse; 06-03-2015, 03:46 PM.
    JoshNinjaTrader Customer Service

    #2
    Applies to NinjaTrader 8

    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. Inside of the if (State == State.SetDefaults) statement, assign a value to the variable for your parameter
      Code:
      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. Please note that the type (int, double, etc) will differ depending on what type of variable you wish to create
      Code:
      [Range(1, int.MaxValue)]
      [NinjaScriptProperty]
      [Display(Name="Period", Description="Numbers of bars used for calculations", Order=1, GroupName="Parameters")]
      public int Period
      { get; set; }
    5. To specify lower and upper bounds, you would modify [Range(1, int.MaxValue)]. For example:
      Code:
      // No upper bound, lower bound of 1
      [Range(1, int.MaxValue)]
      
      // No lower bound, upper bound of 100
      [Range(int.MinValue, 100)]
      
      // No lower or upper bound
      [Range(int.MinValue, int.MaxValue)]
    6. Use the "Description" field to provide a brief description of what the parameter does.
    7. 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
    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
    Last edited by NinjaTrader_Jesse; 06-11-2015, 07:16 AM.
    Zachary G.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by enzo_, Today, 05:07 PM
    1 response
    2 views
    0 likes
    Last Post NinjaTrader_ShawnB  
    Started by Trader17, Today, 02:05 PM
    3 responses
    12 views
    0 likes
    Last Post i2w8am9ii2  
    Started by gbux11, Today, 05:11 PM
    0 responses
    2 views
    0 likes
    Last Post gbux11
    by gbux11
     
    Started by istock999, Today, 04:30 PM
    0 responses
    2 views
    0 likes
    Last Post istock999  
    Started by jmneto, Today, 04:16 PM
    0 responses
    0 views
    0 likes
    Last Post jmneto
    by jmneto
     
    Working...
    X