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 fitspressoburnfat, Today, 04:25 AM
          0 responses
          2 views
          0 likes
          Last Post fitspressoburnfat  
          Started by Skifree, Today, 03:41 AM
          1 response
          4 views
          0 likes
          Last Post Skifree
          by Skifree
           
          Started by usazencort, Today, 01:16 AM
          0 responses
          1 view
          0 likes
          Last Post usazencort  
          Started by kaywai, 09-01-2023, 08:44 PM
          5 responses
          603 views
          0 likes
          Last Post NinjaTrader_Jason  
          Started by xiinteractive, 04-09-2024, 08:08 AM
          6 responses
          23 views
          0 likes
          Last Post xiinteractive  
          Working...
          X