Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Range bar issue with ninjascript

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

    #16
    Ok, thanks!

    Comment


      #17
      That's whacked 89.54=89.54

      but not in IF statement?




      double d1;
      double d2;
      double d3;
      double d4;

      d1 = Close[1] + 4 *TickSize;
      d2 = 4*TickSize;
      d3 = Close[1];
      d4 = d2-d3;

      Print ("ToTime(Time[0])=" + ToTime(Time[0]) +" Close[0]=" + Close[0] + " Close[1]=" + Close[1] + " TickSize=" + TickSize + " (4*TickSize)=" + (4*TickSize) +
      " Close[1]+4*TickSize=" + (Close[1]-4*TickSize) + " Close[1]-4*TickSize=" + (Close[1]-4*TickSize) + " d1=" + d1);
      Print ("d2=" + d2 + " d3=" + d3 + " d4=" + d4 );

      if (d4==Close[0])
      {
      Print ( "D4=Close[0]");
      }
      else
      Print ( "D4!=Close[0]");

      ToTime(Time[0])=110603 Close[0]=89.54 Close[1]=89.58 TickSize=0.01 (4*TickSize)=0.04 Close[1]+4*TickSize=89.54 Close[1]-4*TickSize=89.54 d1=89.62
      d2=0.04 d3=89.58 d4=-89.54
      D4!=Close[0]





      Originally posted by gain247 View Post
      Hi sledge, I've looked at print statements on these situations and they don't show any partial ticks, just same exact tick values as the corresponding bars on the screen. That's why I've been so puzzled as the bars on the screen AND print statements don't sometimes match with the strategy logic execution (or lack of) in certain bar sequences. For that purpose I did a very simple example strategy below to pinpoint some bar close price value issues, and it seems that sometimes (quite frequently) the real Close of the bar is not an exact tick value, but maybe tiny fraction higher/lower. On the screen the tick values are automatically by exact tick increment, but it seems in the world of programming tick is not an exact tick.

      Comment


        #18
        Hello,
        Please refer to this post which further discusses it


        Please let me know if I can assist you any further.
        JoydeepNinjaTrader Customer Service

        Comment


          #19
          You cannot compare double values for equality and expect to get the precision you're expecting all the time. You either have to take the absolute value of their difference and compare that to be less than a threshold level (e.g., diff < 0.0000001f) or convert the doubles to the decimal type in C# and then do the equality comparison on the decimal variables.

          NEVER compare two double values like this:

          if (val1 == val2)...

          The diff method is clumsy looking code but it's faster than working with decimal values as they are not native floating point types.
          Last edited by hygm; 07-29-2012, 08:13 AM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by i019945nj, 12-14-2023, 06:41 AM
          7 responses
          81 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by timmbbo, 07-05-2023, 10:21 PM
          4 responses
          158 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by tkaboris, Today, 08:01 AM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by Lumbeezl, 01-11-2022, 06:50 PM
          31 responses
          818 views
          1 like
          Last Post NinjaTrader_Adrian  
          Started by xiinteractive, 04-09-2024, 08:08 AM
          5 responses
          15 views
          0 likes
          Last Post NinjaTrader_Erick  
          Working...
          X