Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
      BertrandNinjaTrader Customer Service

      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 JoMoon2024, Today, 06:56 AM
          0 responses
          6 views
          0 likes
          Last Post JoMoon2024  
          Started by Haiasi, 04-25-2024, 06:53 PM
          2 responses
          17 views
          0 likes
          Last Post Massinisa  
          Started by Creamers, Today, 05:32 AM
          0 responses
          5 views
          0 likes
          Last Post Creamers  
          Started by Segwin, 05-07-2018, 02:15 PM
          12 responses
          1,786 views
          0 likes
          Last Post Leafcutter  
          Started by poplagelu, Today, 05:00 AM
          0 responses
          3 views
          0 likes
          Last Post poplagelu  
          Working...
          X