Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can I Put Rules on Parameters?

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

    Can I Put Rules on Parameters?

    For example, I have a parameter that must be an integer.... that's easy, I can do that with type, but what if it needs to be an even integer?

    I can force convert Odd to Even in code in the initialize event by changing an odd Parameter entered by the user to an even one, but is there a way to reject the Odd Parameter on user input, with some feedback to the user, so they know they have to select an even integer?

    I can envision other times when such logic could be useful.

    #2
    Hello Crassius,

    Yes, this can be custom coded but would generally be outside our scope of support. You will likely want to look into the mod operator % which returns the remainder of two values.

    We enforce minimum values for public inputs through the Set statement in the block below, so you could work within there to enforce even or odd.

    [Description("Numbers of bars used for calculations")]
    [GridCategory("Parameters")]
    public int Period
    {
    get { return period; }
    set { period = Math.Max(1, value); }
    }


    Example % operator:
    if (someValue % 2 != 0)
    Print("This value is not evenly divisible by 2");
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by Crassius View Post
      For example, I have a parameter that must be an integer.... that's easy, I can do that with type, but what if it needs to be an even integer?

      I can force convert Odd to Even in code in the initialize event by changing an odd Parameter entered by the user to an even one, but is there a way to reject the Odd Parameter on user input, with some feedback to the user, so they know they have to select an even integer?

      I can envision other times when such logic could be useful.
      Divide the integer by 2, then multiply the result by 2. If the number is odd, the division will discard the half, so when you multiply the result by 2, you will end up with an even number.

      Comment


        #4
        Thank you both for the quick responses.

        Comment


          #5
          Forces Even by adding 1 if it detects an odd value.

          [Description("Numbers of bars used for calculations")]
          [GridCategory("Parameters")]
          public int Period
          {
          get { return period; }
          set { period = Math.Max(1, value % 2 == 0 ? value: value + 1); }
          }

          Forces Odd by adding 1 if it detects an even value.

          [Description("Numbers of bars used for calculations")]
          [GridCategory("Parameters")]
          public int Period
          {
          get { return period; }
          set { period = Math.Max(1, value % 2 == 1 ? value: value + 1); }
          }
          Ryan M.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          581 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          338 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          103 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          554 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          552 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X