Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bid and ask rouding

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

    Bid and ask rouding

    NinjaTrader 7.0.1000.31
    I am try to calculate trall like this

    PHP Code:
    double new_trall;
    new_trall = GetCurrentBid() - stop_loss2 * TickSize; 
    
    And sometimes i have results like this:

    new_trall = 1057.6000000000001
    stop_loss2 = 8
    TickSize = 0.1
    GetCurrentBid() = 1058.4

    Why? And how i can get correct result?
    Last edited by Dzammer; 03-22-2016, 11:34 AM.

    #2
    Hello,

    Thank you for the question.

    I see that the majority of the result is correct, are you referring to the remainder left over? This can happen with floating point math, there is a more clear description of common issues here: http://ninjatrader.com/support/forum...ead.php?t=3929

    If you want to ensure the value is a valid price value aligned with a TickSize, you could use the Round2TickSize method to ensure the output is always a valid price.

    Code:
    Instrument.MasterInstrument.Round2TickSize(GetCurrentBid() - (stop_loss2 * TickSize));
    Otherwise to maintain the value with a limited remainder, the Math.Round method could be used to Round it to X number of places:

    Code:
    Math.Round(GetCurrentBid() - (stop_loss2 * TickSize), 2);

    I look forward to being of further assistance.

    Comment


      #3
      Thank you.

      Code:
      Instrument.MasterInstrument.Round2TickSize(GetCurrentBid() - (stop_loss2 * TickSize));
      It's worked for me.

      Comment

      Latest Posts

      Collapse

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