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 Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          581 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          338 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          103 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          554 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          552 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X