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 Waxavi, Today, 02:10 AM
      0 responses
      3 views
      0 likes
      Last Post Waxavi
      by Waxavi
       
      Started by TradeForge, Today, 02:09 AM
      0 responses
      9 views
      0 likes
      Last Post TradeForge  
      Started by Waxavi, Today, 02:00 AM
      0 responses
      2 views
      0 likes
      Last Post Waxavi
      by Waxavi
       
      Started by elirion, Today, 01:36 AM
      0 responses
      4 views
      0 likes
      Last Post elirion
      by elirion
       
      Started by gentlebenthebear, Today, 01:30 AM
      0 responses
      4 views
      0 likes
      Last Post gentlebenthebear  
      Working...
      X