Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error in Calculations

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

    Error in Calculations

    hi, i am trying simple print:

    hr=High[0]-Low[0];
    Print(hr);

    while the stock is a 2 fraction stock
    i am getting output like this:

    0.0800000000000125
    0.0699999999999932
    0.0499999999999829
    0.0600000000000023
    0.0999999999999943
    0.0500000000000114
    0.0800000000000125
    0.0500000000000114
    0.0600000000000023
    0.039999999999992
    0.0600000000000023
    0.0800000000000125

    Why???
    if the h[0]=12.1
    and l[0]=12
    i must get aprinted value of 0.1
    not 0.099999999999999

    why is this annoying error??

    #2
    You're working with true double values here, so floating point arithmetic issues need to be considered as explained here - http://www.ninjatrader.com/support/f...ead.php?t=3929
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      You're working with true double values here, so floating point arithmetic issues need to be considered as explained here - http://www.ninjatrader.com/support/f...ead.php?t=3929
      you referred to a thread about comparing double to double.
      but what if i have more complex calculations?? like i am converting my system from TS to NT, i am getting totally different signals because of this small difference, why? because i keep doing more & more complex calculations until the double variable have a big difference from its theoretical value...
      any other suggestion?

      Comment


        #4
        Correct working strongly with doubles and the precision they offer can result in 'blowing up' calculations by not properly debugging scenarios created by the code. You could for example use less precision (it's seldom needed in the final results) which would also use less memory then (floats for example).
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Originally posted by xbaha View Post
          you referred to a thread about comparing double to double.
          but what if i have more complex calculations?? like i am converting my system from TS to NT, i am getting totally different signals because of this small difference, why? because i keep doing more & more complex calculations until the double variable have a big difference from its theoretical value...
          any other suggestion?
          If you are working with price data, just round all your results to TickSize, and that should handle it. Yes, that means intermediate results too. Calculating anything to 15 decimal points when the input data is to 2 decimal points does not increase precision. Actually, it could very well decrease it, as the so-called extra precision is really noise. And that even seems to be what you are seeing in practical terms.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by BarzTrading, Today, 07:25 AM
          2 responses
          27 views
          1 like
          Last Post BarzTrading  
          Started by devatechnologies, 04-14-2024, 02:58 PM
          3 responses
          20 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by tkaboris, Today, 08:01 AM
          0 responses
          6 views
          0 likes
          Last Post tkaboris  
          Started by EB Worx, 04-04-2023, 02:34 AM
          7 responses
          163 views
          0 likes
          Last Post VFI26
          by VFI26
           
          Started by Mizzouman1, Today, 07:35 AM
          1 response
          11 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X