Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Compare absolute values

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

    Compare absolute values

    Hello,
    In my code I want an absolute (no matter + or -) value of one indicator be not more than one point differ from the absolute value of another indicator.
    So I wrote && (SMA1[0] < (VMA1[0] + 1) ).
    But sometimes VMA1[0] is higher than SMA1[0] and true will be && (VMA1[0] < (SMA1[0] + 1) ) for the same direction.
    What would be the right way to compare absolute values?
    Thank you so much.
    ​​

    #2
    Try:
    if(Math.Abs(SAM1[0] - VMA1[0]) > 1)
    Do Something.

    What is 1? 1 point? 1 tick? You need to possibly specify.
    eDanny
    NinjaTrader Ecosystem Vendor - Integrity Traders

    Comment


      #3
      an absolute (no matter + or -) value of one indicator be not more than one point differ from the absolute value of another indicator.
      Anybody knows how to write it?

      Comment


        #4
        You might want to break it down to the smallest movement of the instrument, or Tick size. You might have trouble with the YM where 1 Point = same as 1 Tick movement. CL has 100 Ticks per bar. If you want Points and were using an instrument with a Tick value of .0000001, 1 Point = 10000000 Ticks of movement. If you use Points, use 1 for one point. Using Ticks, 10 Ticks = 10*TickSize.

        if(Math.Abs(SAM1[0] - VMA1[0]) < 10 * TickSize)

        BTW, 10 Ticks YM = 10 Points
        10 Ticks ES = 2.5 Points
        10 Ticks CL = .10 (1 Point = $1.00, 10 Ticks = $.10 or 10 cents)
        eDanny
        NinjaTrader Ecosystem Vendor - Integrity Traders

        Comment


          #5
          Hello eDanny, thank you for reply

          If you just read my post, I do not have any troubles. All I want is to compare absolute (mean no + no -) values of two different indicators. And my question is how to write it in the code

          Comment


            #6
            Your example ( f(Math.Abs(SAM1[0] - VMA1[0]) < 10 * TickSize)) will work fine. But what if VMA is bigger than SMA for the same direction. May you include both cases in one code?

            Comment


              #7
              Depending on which is larger, you will get either a positive or negative answer which you take the absolute value of to always make a positive.
              eDanny
              NinjaTrader Ecosystem Vendor - Integrity Traders

              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