Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Absolute Value problem

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

    Absolute Value problem

    I am trying to determine the absolute value of the current close and can not get the function to work using:

    cLine = (Math.Abs(Close[0]));
    Print ("Bar="+CurrentBar+ "Cline="+cLine);

    The value printed for cLine is the bars closing price say 56.54 instead of 56

    Can anybody tell me what I am doing wrong?

    Ryan

    #2
    Absolute Value returns the positive of a #.

    It doesn't round or truncate, which is probably what you are looking for.


    Comment


      #3
      Ryan, from your example then what you want to use is Math.Truncate instead. Then you don't have to deal with rounding modes, but just keep the integer part.

      Comment


        #4
        Originally posted by RyanR View Post
        I am trying to determine the absolute value of the current close and can not get the function to work using:

        cLine = (Math.Abs(Close[0]));
        Print ("Bar="+CurrentBar+ "Cline="+cLine);

        The value printed for cLine is the bars closing price say 56.54 instead of 56

        Can anybody tell me what I am doing wrong?

        Ryan
        The raw value is 56.54.

        If you want cLine to be 56 (the integer part) --> use Math.Truncate(Close[0]);
        If you want cLine to be 57 (the nearest integer) --> use Convert.ToInt32(Close[0]);

        Thanks.
        Pi
        ninZa
        NinjaTrader Ecosystem Vendor - ninZa.co

        Comment


          #5
          Thanks for the replies...I knew it was something obviously wrong...like the wrong function!!!
          Note to self...No coding without sleep!

          Ryan

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Hwop38, 05-04-2026, 07:02 PM
          0 responses
          160 views
          0 likes
          Last Post Hwop38
          by Hwop38
           
          Started by CaptainJack, 04-24-2026, 11:07 PM
          0 responses
          307 views
          0 likes
          Last Post CaptainJack  
          Started by Mindset, 04-21-2026, 06:46 AM
          0 responses
          244 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by M4ndoo, 04-20-2026, 05:21 PM
          0 responses
          348 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by M4ndoo, 04-19-2026, 05:54 PM
          0 responses
          178 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Working...
          X