Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

property range validation

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

    property range validation

    Is there a way to Validate a range of number that can be entered as property input.

    Is there an attribute I can use ? Something like [Range(0-4)] ?


    Thank you

    #2
    Hi blar58,

    Yes, you can use Math.Max() and Math.Min() to restrict the range of inputs in a property. See this post for help with inputs and an example minimum:


    To set the upper-bound as well, nest multiple statements together, like:
    [Description("Numbers of bars used for calculations")]
    [GridCategory("Parameters")]
    public int Period
    {
    get { return period; }
    set { period = Math.Min(Math.Max(1, value), 4); }
    }
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Ryan

      Yes I knew about this but let's say I enter 105 and the acceptable range value is 0-4 so I put Math.Min(4,value) 4 will be the result. would like it to be 0 if it is greater than 4.

      Is there a way around it

      Thanks

      Comment


        #4
        OK Ryan I figured that out.

        Thanks

        Comment


          #5
          You could build your own logic there to handle inputs exactly as you like.

          If the value inputted is over 4, make it 0. Otherwise the value must be at least 0:

          Code:
          [Description("")]
          [GridCategory("Parameters")]
          public int MyInput0
          {
               get { return myInput0; }
               set { myInput0 = value > 4 ? 0 : Math.Max(value, 0); }
          }
          Ryan M.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Segwin, 05-07-2018, 02:15 PM
          14 responses
          1,789 views
          0 likes
          Last Post aligator  
          Started by Jimmyk, 01-26-2018, 05:19 AM
          6 responses
          837 views
          0 likes
          Last Post emuns
          by emuns
           
          Started by jxs_xrj, 01-12-2020, 09:49 AM
          6 responses
          3,293 views
          1 like
          Last Post jgualdronc  
          Started by Touch-Ups, Today, 10:36 AM
          0 responses
          13 views
          0 likes
          Last Post Touch-Ups  
          Started by geddyisodin, 04-25-2024, 05:20 AM
          11 responses
          63 views
          0 likes
          Last Post halgo_boulder  
          Working...
          X