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([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 SalmaTrader, 07-07-2026, 10:26 PM
      0 responses
      26 views
      0 likes
      Last Post SalmaTrader  
      Started by CarlTrading, 07-05-2026, 01:16 PM
      0 responses
      15 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 06-17-2026, 10:32 AM
      0 responses
      9 views
      0 likes
      Last Post CaptainJack  
      Started by kinfxhk, 06-17-2026, 04:15 AM
      0 responses
      10 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Started by kinfxhk, 06-17-2026, 04:06 AM
      0 responses
      17 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Working...
      X