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 alifarahani, Today, 09:40 AM
      4 responses
      21 views
      0 likes
      Last Post alifarahani  
      Started by gentlebenthebear, Today, 01:30 AM
      3 responses
      16 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by PhillT, Today, 02:16 PM
      2 responses
      7 views
      0 likes
      Last Post PhillT
      by PhillT
       
      Started by Kaledus, Today, 01:29 PM
      3 responses
      11 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by frankthearm, Yesterday, 09:08 AM
      14 responses
      47 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Working...
      X