Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Difference in price not exact

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

    Difference in price not exact

    If you calculate the difference between 2 prices (let's say High[3] - High[0]) and print them you'll never get a round result for a CL contract. If there is a 5 ticks difference it will show 0.050000000000006 or 0.0499999999999963
    In my case it makes a big difference in a strategy profitability if I round or not these values.
    It's consistently much more profitable when the difference is below 0.05 than above 0.05. Do you have any ideas what determines that the difference will be slightly above or below the theoretical value as it seems to obey to a kind of logic ? (at least in my strategy)
    Last edited by bluesoul40; 05-02-2025, 12:13 PM.

    #2
    I think it has to do with rounding to the nearest float number. I need to study this https://ninjatrader.com/support/help...arithmetic.htm

    Comment


      #3
      Hello bluesoul40,

      In C# math between doubles can result in long numbers for decimals. You can use Math.Round to round a number to a specific place. If you want the tick size you can use RoundToTickSize


      Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


      Rounds a value to the nearest integer or to the specified number of fractional digits.

      Comment


        #4
        Thank you. In fact my strategy is working with 2 different logics. The one involving this rounding is the less profitable and because of the rounding issue it was showing less trades, showing better results

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        60 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        39 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        21 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        23 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        51 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X