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

Rounded numbers from print statement

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

    Rounded numbers from print statement

    Hi Folks,

    Newbee question: I want to express one value in relation to another as a percentage. When testing this in the output window I get rounded numbers only, either 1 or 0.

    The variable I tried is both double and float but output stays the same, the statement is below:

    _50PercDelta = (barsType.Volumes[CurrentBar].TotalVolume + barsType.Volumes[CurrentBar].MinSeenDelta) / barsType.Volumes[CurrentBar].TotalVolume;

    What am I missing here?


    #2
    Hello Diepy,

    Thanks for your post.

    We are seeing the result of integer math being assigned to a double because you are performing mathematical operations on integers and assigning the result to a double.

    You could consider casting (publicly available resource) the integers to type double, and we will then see a result from floating point arithmetic.

    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thanks Jim, that makes sense.

      So double would be fine for my purposes and I figured I would alter the statement like below.

      _50PercDelta = Convert.ToDouble((barsType.Volumes[CurrentBar].TotalVolume + barsType.Volumes[CurrentBar].MinSeenDelta)/ barsType.Volumes[CurrentBar].TotalVolume)

      The output window still shows rounded numbers though, anything I am missing still?

      Thanks

      Comment


        #4
        Hello Diepy,

        You are still performing math on integers, getting a result from integer math, AND THEN you are converting to a double, and assigning to the double variable.

        Try casting the integers before performing the math. I.E.

        ((double)(barsType.Volumes[CurrentBar].TotalVolume) + (double)(barsType.Volumes[CurrentBar].MinSeenDelta) / (double)(barsType.Volumes[CurrentBar].TotalVolume;

        OR

        (Convert.ToDouble(barsType.Volumes[CurrentBar].TotalVolume) + Convert.ToDouble(barsType.Volumes[CurrentBar].MinSeenDelta) / Convert.ToDouble(barsType.Volumes[CurrentBar].TotalVolume;
        JimNinjaTrader Customer Service

        Comment


          #5
          Thanks Jim, I see I was a too lazy programmer :-) Your suggestion did the trick, thanks for the help!



          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by algospoke, Yesterday, 06:40 PM
          2 responses
          24 views
          0 likes
          Last Post algospoke  
          Started by ghoul, Today, 06:02 PM
          3 responses
          15 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          46 views
          0 likes
          Last Post jeronymite  
          Started by Barry Milan, Yesterday, 10:35 PM
          7 responses
          23 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by AttiM, 02-14-2024, 05:20 PM
          10 responses
          181 views
          0 likes
          Last Post jeronymite  
          Working...
          X