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 Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            603 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            349 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            104 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            560 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            560 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X