Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bar Types - the use on Compare

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

    Bar Types - the use on Compare

    Hello,

    In looking through the NinjaScript.BarTypes I notice there are variants of Compare used;

    In Range Bars;
    if (close.ApproxCompare(barLow + rangeValue) > 0)

    In LineBreakBars;
    if (bars.Instrument.MasterInstrument.Compare(bars.Get Close(bars.Count - 1), anchorPrice) > 0)

    and in NinjaScript intellisense there is also available;
    if(close.CompareTo(barHigh - rangeVale) > 0)

    Each of these variants would appear to do the same - are there situations where one would be favored over another?

    And separately - in what way are they better than say;
    if(close < barHigh - rangeValue)

    Thank you

    #2
    .ApproxCompare() is an extension method we use for double values which helps account for floating point issues

    There are some classes such as the MasterInstrument which have methods called Compare(), but internally those methods will be using the ApproxCompare() method which also account for double floating points.

    .CompareTo() is a .NET method which sometimes fails with floating point issues per the remarks in this MSDN page: https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

    As a result, we implemented the ApproxCompare() to help in these situations

    Separately, if you just tested:

    Code:
    if(close < barHigh - rangeValue)
    You could run into issues with floating point decimals and the test might fail, whereas "ApproxCompare" would not
    Last edited by NinjaTrader_Matthew; 11-03-2015, 01:09 PM.
    MatthewNinjaTrader Product Management

    Comment


      #3
      Thank you for your reply Matthew.

      I think I understand now, however I will also check the MSDN page as you suggest.

      Thanks again,

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by argusthome, Yesterday, 10:06 AM
      0 responses
      21 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      18 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      14 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      9 views
      0 likes
      Last Post TheRealMorford  
      Started by Mindset, 02-28-2026, 06:16 AM
      0 responses
      40 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X