Announcement

Collapse
No announcement yet.

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:
    http://www.ninjatrader.com/support/f...ead.php?t=5782

    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 Unsuitable, Today, 07:26 PM
          0 responses
          1 view
          0 likes
          Last Post Unsuitable  
          Started by jvanelli, Today, 06:36 PM
          2 responses
          9 views
          0 likes
          Last Post NinjaTrader_EricB  
          Started by twitch251, Today, 05:14 PM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_ShawnB  
          Started by robforee2, Today, 05:07 PM
          0 responses
          4 views
          0 likes
          Last Post robforee2  
          Started by blar58, Today, 03:16 PM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_Melissa  
          Working...
          X