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.
    JesseNinjaTrader Customer Service

    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 Felix Reichert, Today, 02:12 PM
      0 responses
      1 view
      0 likes
      Last Post Felix Reichert  
      Started by Tim-c, Today, 02:10 PM
      0 responses
      1 view
      0 likes
      Last Post Tim-c
      by Tim-c
       
      Started by cre8able, Today, 01:16 PM
      2 responses
      9 views
      0 likes
      Last Post cre8able  
      Started by chbruno, 04-24-2024, 04:10 PM
      3 responses
      48 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by samish18, Today, 01:01 PM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_LuisH  
      Working...
      X