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

Reporting an error

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

    Reporting an error

    Not sure where to post this, so I will do it here.

    I have been debugging an indicator and it has been having odd problems. I have finally narrowed it down to a problem with NinjaScript, and not my code.

    This is the code in question:
    Code:
    Math.Abs(HLBP - HLAP)
    HLBP = 142.006 and HLAP = 141.549. The result I expected to get was 0.457. The result I am getting is 0.456999999999994.

    While it may not seem like a big issue, it is causing problems. Plus, the returned result is wrong.

    #2
    Thanks for the post Antny, you would need to keep in mind that under the hood you're working with the full precision a C# double value has to offer. As computers calculate in binary format, representing floating point arithmetic can oftentimes only be an approximation to a certain precision. This tip on our forums will discuss this in more depth - http://www.ninjatrader.com/support/f...ead.php?t=3929
    BertrandNinjaTrader Customer Service

    Comment


      #3
      I had considered this. Three decimal places is well within the precision of the double limitations. There should not be a rounding error with a simple subtraction of two small doubles, both with less than three points of precision.

      Comment


        #4
        How do you determine the values of HLBP and HLAP? Are those doubles as well? Would you have perhaps a code snippet I can run at my end?
        BertrandNinjaTrader Customer Service

        Comment


          #5
          They are bid prices. In this particular instance, they were prices on a GBPJPY chart. I did some checking and this seems to happen quite often. Some instances did return the correct value, but often, it was a large decimal. To test it, you should be able to just enter random price values into the two variables.

          Comment


            #6
            Hi Antny,

            While the bid values you are using may be 3 decimals when it prints, but the issue with the floating point arithmetic is that the computer is storing approximations of these values. This means that you can end up with large decimals when doing math with these values.

            I do think that the issue you are running into is with floating point arithmetic.

            There is a description of the issue in the following link:
            http://www.ninjatrader.com/support/f...ead.php?t=3929
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              I am inclined to agree after having seen how often it occurs. Oh well.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by jpeep, 08-16-2020, 08:31 AM
              17 responses
              502 views
              0 likes
              Last Post notenufftime  
              Started by ETFVoyageur, 05-07-2024, 07:05 PM
              15 responses
              124 views
              0 likes
              Last Post ETFVoyageur  
              Started by esmall, Today, 07:14 PM
              0 responses
              9 views
              0 likes
              Last Post esmall
              by esmall
               
              Started by Option Whisperer, 05-09-2024, 07:58 PM
              6 responses
              26 views
              0 likes
              Last Post Option Whisperer  
              Started by rayyyu12, Today, 05:38 PM
              0 responses
              12 views
              0 likes
              Last Post rayyyu12  
              Working...
              X