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 [COLOR=red]period[/COLOR]; }
           set { [COLOR=red]period[/COLOR] = 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 [COLOR=red]int[/COLOR] 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.
    Josh P.NinjaTrader 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 [COLOR=red]int[/COLOR] 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 manitshah915, Today, 12:59 PM
    1 response
    3 views
    0 likes
    Last Post NinjaTrader_Erick  
    Started by ursavent, Today, 12:54 PM
    1 response
    3 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by cre8able, Today, 01:01 PM
    1 response
    4 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by Mizzouman1, Today, 07:35 AM
    3 responses
    17 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by RubenCazorla, Today, 09:07 AM
    2 responses
    13 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X