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 terofs, Yesterday, 04:18 PM
      1 response
      21 views
      0 likes
      Last Post terofs
      by terofs
       
      Started by CommonWhale, Today, 09:55 AM
      1 response
      3 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by Gerik, Today, 09:40 AM
      2 responses
      7 views
      0 likes
      Last Post Gerik
      by Gerik
       
      Started by RookieTrader, Today, 09:37 AM
      2 responses
      13 views
      0 likes
      Last Post RookieTrader  
      Started by alifarahani, Today, 09:40 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X