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

Strange Data Type Issue

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

    Strange Data Type Issue

    Hi,

    I was trying to perform an order of magnitude calculation when I ran into the following issue:

    double rawPrice = (Open[0] + High[0] + Low[0] + Close[0]) * 0.25;
    int magnitude = Math.Floor(Math.Log10(Math.Abs(rawPrice)));

    This will not compile even though it should.

    I had to do an explicit cast to get this to compile; i.e.

    double rawPrice = (Open[0] + High[0] + Low[0] + Close[0]) * 0.25;
    int magnitude = (int)Math.Floor(Math.Log10(Math.Abs(rawPrice)));

    Am I missing something here? Please advise. Thank you very much.

    #2
    Hello,

    I dont see an issue. This would be expected and is part of c# programming language.

    Datatype that you did the math functions to was of oringal type double. Therefor no matter what calculations you do, even if the double turns into what would fit nicely in an int. It is still a double (Due to the memory assigned for the var) and the compiler will flag you with error if you attempt to assign this to an int.

    Therefor to get the compile to let you compile you must put the type cast in to tell the compile you know what your doing and its ok if data loss occurs. (Even though in your case most likely no data loss if the value no longer has a decimal after it.)

    Let me know if I can be of further assistance.

    Comment


      #3
      Hi Brett,

      My apologies. Of course you are correct. This was a dumb question on my part - brain freeze. Just couldn't see it at the time. Sorry to have taken up your time.
      Thank you for your reply.

      Comment


        #4
        No problem, glad to be of help.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Jonafare, 12-06-2012, 03:48 PM
        5 responses
        3,984 views
        0 likes
        Last Post rene69851  
        Started by Fitspressorest, Today, 01:38 PM
        0 responses
        2 views
        0 likes
        Last Post Fitspressorest  
        Started by Jonker, Today, 01:19 PM
        0 responses
        2 views
        0 likes
        Last Post Jonker
        by Jonker
         
        Started by futtrader, Today, 01:16 PM
        0 responses
        6 views
        0 likes
        Last Post futtrader  
        Started by Segwin, 05-07-2018, 02:15 PM
        14 responses
        1,791 views
        0 likes
        Last Post aligator  
        Working...
        X