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 pmachiraju, 11-01-2023, 04:46 AM
      8 responses
      147 views
      0 likes
      Last Post rehmans
      by rehmans
       
      Started by mattbsea, Today, 05:44 PM
      0 responses
      5 views
      0 likes
      Last Post mattbsea  
      Started by RideMe, 04-07-2024, 04:54 PM
      6 responses
      33 views
      0 likes
      Last Post RideMe
      by RideMe
       
      Started by tkaboris, Today, 05:13 PM
      0 responses
      5 views
      0 likes
      Last Post tkaboris  
      Started by GussJ, 03-04-2020, 03:11 PM
      16 responses
      3,282 views
      0 likes
      Last Post Leafcutter  
      Working...
      X