• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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(0, 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 mreanuzlazx, Today, 01:30 AM
      0 responses
      1 view
      0 likes
      Last Post mreanuzlazx  
      Started by xinepev, Today, 12:33 AM
      0 responses
      4 views
      0 likes
      Last Post xinepev
      by xinepev
       
      Started by sun0781, Yesterday, 05:02 PM
      0 responses
      7 views
      0 likes
      Last Post sun0781
      by sun0781
       
      Started by ronhb107, 09-12-2019, 10:09 AM
      4 responses
      44 views
      0 likes
      Last Post Mr.Trader  
      Started by rwilliam, Yesterday, 03:55 PM
      0 responses
      4 views
      0 likes
      Last Post rwilliam  
      Working...
      X