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 jclose, Today, 09:37 PM
    0 responses
    5 views
    0 likes
    Last Post jclose
    by jclose
     
    Started by WeyldFalcon, 08-07-2020, 06:13 AM
    10 responses
    1,413 views
    0 likes
    Last Post Traderontheroad  
    Started by firefoxforum12, Today, 08:53 PM
    0 responses
    11 views
    0 likes
    Last Post firefoxforum12  
    Started by stafe, Today, 08:34 PM
    0 responses
    11 views
    0 likes
    Last Post stafe
    by stafe
     
    Started by sastrades, 01-31-2024, 10:19 PM
    11 responses
    169 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Working...
    X