Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using Decimals In Parameters

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

    Using Decimals In Parameters

    Hello staff,

    I created an indicator that I am using in conjunction with auto-scaling to centre the price bars on my chart. I am however not able to put decimals in the two parameters that I have.
    Here's the simple code I'm using.


    protected override void OnBarUpdate()
    {
    Values[0][0] = Open[0] + HighOffset;
    Values[1][0] = Open[0] - LowOffset;
    }

    #region Properties
    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="HighOffset", Order=1, GroupName="Parameters")]
    public int HighOffset
    { get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="LowOffset", Order=2, GroupName="Parameters")]
    public int LowOffset
    { get; set; }


    Is there any way to allow decimals in the parameters so that I can use this indicator on markets with decimals in the price (eg. ES, NQ)?

    Thank you in advance for your reply!

    #2
    The problem for you is that HighOffset and LowOffset variables are defined as integers. Change them to doubles and you will be golden.
    eDanny
    NinjaTrader Ecosystem Vendor - Integrity Traders

    Comment


      #3
      Hello GLFX005,

      Thank you for your post.

      You're declaring those as being int variables. You want to use a double instead:

      Code:
              [NinjaScriptProperty]
              [Range(1, double.MaxValue)]
              [Display(Name="HighOffset", Order=1, GroupName="Parameters")]
              public double HighOffset
              { get; set; }
      
              [NinjaScriptProperty]
              [Range(1, double.MaxValue)]
              [Display(Name="LowOffset", Order=1, GroupName="Parameters")]
              public double LowOffset
              { get; set; }
      Please let us know if we may be of further assistance to you.

      Comment


        #4
        Hello Kate, thank you for your reply.

        I have applied the changes to my script and I am now able to use decimals. However, I am still not able to use something that is less than 1, like "0.50". The "1.50" does work.
        Can this be resolved?

        I'm looking forward to your reply.

        Comment


          #5
          Hello GLFX005,

          Thank you for your reply.

          That's my error - change this line:

          Code:
                  [Range(1, double.MaxValue)]
          To:

          Code:
                  [Range(0.01, double.MaxValue)]
          For both. This way you can use values less than 1. Please let us know if we may be of further assistance to you.

          Comment


            #6
            Hello Kate,

            Thank you for your assistance, I appreciate it a lot.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by CarlTrading, 03-31-2026, 09:41 PM
            1 response
            80 views
            1 like
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            40 views
            0 likes
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            63 views
            2 likes
            Last Post CaptainJack  
            Started by CarlTrading, 03-30-2026, 11:51 AM
            0 responses
            63 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 03-30-2026, 11:48 AM
            0 responses
            54 views
            0 likes
            Last Post CarlTrading  
            Working...
            X