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 Tim-c, Today, 03:54 AM
          0 responses
          3 views
          0 likes
          Last Post Tim-c
          by Tim-c
           
          Started by FrancisMorro, Today, 03:24 AM
          0 responses
          2 views
          0 likes
          Last Post FrancisMorro  
          Started by Segwin, 05-07-2018, 02:15 PM
          10 responses
          1,770 views
          0 likes
          Last Post Leafcutter  
          Started by Rapine Heihei, 04-23-2024, 07:51 PM
          2 responses
          31 views
          0 likes
          Last Post Max238
          by Max238
           
          Started by Shansen, 08-30-2019, 10:18 PM
          24 responses
          945 views
          0 likes
          Last Post spwizard  
          Working...
          X