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 argusthome, 03-08-2026, 10:06 AM
          0 responses
          65 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          41 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          23 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          26 views
          0 likes
          Last Post TheRealMorford  
          Started by Mindset, 02-28-2026, 06:16 AM
          0 responses
          52 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Working...
          X