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

Problem with double variables

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

    Problem with double variables

    Hello, I am trying to make a small change to an indicator I use.
    It uses a private double variable and when this variable is set to values above 1 like 1.9 it works as expected. But when I try to set a value of say 0.9, it resets later to 1, as if values bellow 1 were not accepted. This behaviour should not exist right?
    After all we re dealing with the correct type of variable.
    The solution I ve come up with is to set the variable double but with an integer value, then in calculations divide it by 1000. It works, but from a programmer perspective it just adds complexity thus calculations to the output of the formula. Makes no sense.

    private double aTRmultiplier = 786

    Am I doing something wrong or have I come across some kind or error?

    Thank you very much

    S C

    #2
    Originally posted by secaarco View Post
    Hello, I am trying to make a small change to an indicator I use.
    It uses a private double variable and when this variable is set to values above 1 like 1.9 it works as expected. But when I try to set a value of say 0.9, it resets later to 1, as if values bellow 1 were not accepted. This behaviour should not exist right?
    After all we re dealing with the correct type of variable.
    The solution I ve come up with is to set the variable double but with an integer value, then in calculations divide it by 1000. It works, but from a programmer perspective it just adds complexity thus calculations to the output of the formula. Makes no sense.

    private double aTRmultiplier = 786

    Am I doing something wrong or have I come across some kind or error?

    Thank you very much

    S C
    Hi S C

    I think this is the solution: open 'Properties' at the base of the script and change the first argument in Math.Max to 0 as below:

    Code:
    public double Name
            {
                get { return name; }
                set { name= Math.Max([COLOR=Red][B]0[/B][/COLOR], value); }
            }
    It took me a long time to work this out myself when I first encountered the problem!

    Comment


      #3
      Regarding the proposed solution by Arbuthnot

      Arbuthnot, your solution worked flawlessly. It turned the variable behaviour as it was expected.
      I thank you very much for this little gem.

      Have a pleasant weekend, enjoy.

      Best, SC

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by JoMoon2024, Today, 06:56 AM
      0 responses
      1 view
      0 likes
      Last Post JoMoon2024  
      Started by Haiasi, 04-25-2024, 06:53 PM
      2 responses
      17 views
      0 likes
      Last Post Massinisa  
      Started by Creamers, Today, 05:32 AM
      0 responses
      5 views
      0 likes
      Last Post Creamers  
      Started by Segwin, 05-07-2018, 02:15 PM
      12 responses
      1,786 views
      0 likes
      Last Post Leafcutter  
      Started by poplagelu, Today, 05:00 AM
      0 responses
      3 views
      0 likes
      Last Post poplagelu  
      Working...
      X