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 AaronKoRn, Today, 09:49 PM
              0 responses
              7 views
              0 likes
              Last Post AaronKoRn  
              Started by carnitron, Today, 08:42 PM
              0 responses
              9 views
              0 likes
              Last Post carnitron  
              Started by strategist007, Today, 07:51 PM
              0 responses
              10 views
              0 likes
              Last Post strategist007  
              Started by StockTrader88, 03-06-2021, 08:58 AM
              44 responses
              3,980 views
              3 likes
              Last Post jhudas88  
              Started by rbeckmann05, Today, 06:48 PM
              0 responses
              9 views
              0 likes
              Last Post rbeckmann05  
              Working...
              X