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

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 lightsun47, Today, 03:51 PM
          0 responses
          4 views
          0 likes
          Last Post lightsun47  
          Started by 00nevest, Today, 02:27 PM
          1 response
          8 views
          0 likes
          Last Post 00nevest  
          Started by futtrader, 04-21-2024, 01:50 AM
          4 responses
          44 views
          0 likes
          Last Post futtrader  
          Started by Option Whisperer, Today, 09:55 AM
          1 response
          13 views
          0 likes
          Last Post bltdavid  
          Started by port119, Today, 02:43 PM
          0 responses
          9 views
          0 likes
          Last Post port119
          by port119
           
          Working...
          X