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

Input Parameter Values Range

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

    Input Parameter Values Range

    Hello, below is a snippet of one of the parameters to an indicator which is then used in a DrawLine call in the code:

    [Description("Width for High line Post touch.")]


    [Category("Plots")]
    [Gui.Design.DisplayNameAttribute("Line Width High Post touch")]
    public int highLineWidthPostTouch
    {
    get { return HighLineWidthPostTouch; }
    set { HighLineWidthPostTouch = Math.Max(1, value); }
    }

    As you are probably aware there is a limit of 10 for the width otherwise a run time exception error is raised when calling DrawLine when the width parameter exceeds 10.

    In the Initialise() body i inserted a check

    if (HighLineWidthPostTouch > 10) HighLineWidthPostTouch = 10;

    What i need is for the value to be between 1 and 10. I was trying to see if there was a way in the parameter section to define a max and min value but in looking around couldnt see a way to do this even with linking parameters one with Min one with Max?

    So i elected to do the check in the initialise ; the issue appears to be that the setting in initialise doesnt seem to work ; i have 6 width parameters and each is used in a separate DrawLine call ; so when the first DrawLine call is made depending on the flow of logic it is raising this error and each has a different width.

    Is there something obvious i need to so in the parameters ie to make it editable ie the initialise code is not taking effect or i need to set the value for the lowercase name
    highLineWidthPostTouch ie the name of the parameter?

    Incidentally is this a Ninja 7 limitation of DrawLine width or is the underlying graphics? I could see no mention of this in the documentation anywhere and happened to stumble on this as it was affecting the logic flow as an exception was being raised,

    Any input appreciated
    thanks

    #2
    Use Min:
    HighLineWidthPostTouch = Math.Max(1, Math.Min(10, value));
    eDanny
    NinjaTrader Ecosystem Vendor - Integrity Traders

    Comment


      #3
      Hello Soulfx,

      Thank you for your note.

      eDanny is correct, thank you eDanny.

      To set an upper limit for a user defined input you’ll want to use, Math.Min() rather than Math.Max as you currently are using.

      So instead of,
      set { HighLineWidthPostTouch = Math.Max(1, value); }

      Use,
      set { HighLineWidthPostTouch = Math.Min(10, value); }

      Or if you’d like to set a minimum value and a max value,
      set { HighLineWidthPostTouch = Math.Max(1, Math.Min(10, value)); }

      Please see Creating user Defined Input Parameters post on the forum.


      Please let us know if you need further assistance.
      Alan P.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Tim-c, Today, 02:10 PM
      0 responses
      1 view
      0 likes
      Last Post Tim-c
      by Tim-c
       
      Started by cre8able, Today, 01:16 PM
      2 responses
      9 views
      0 likes
      Last Post cre8able  
      Started by chbruno, 04-24-2024, 04:10 PM
      3 responses
      48 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by samish18, Today, 01:01 PM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_LuisH  
      Started by WHICKED, Today, 12:56 PM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Working...
      X