Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculating if Close[0] is a round number

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

    Calculating if Close[0] is a round number

    Hi,
    I am trying to calculate the current price in order to see if it is a round number....but can't seem to figure out a way to do it.

    I am thinking of dividing Close[0] by a variable and then verifying if it is an integer.


    {Close[0] / 50 = var1;}

    And then to check if Var1 == whole number


    Any input would be greatly appreciated.

    Thanks.

    #2
    Hello,
    Thanks for posting today.

    Can you give a little clarification of what you mean by a round number? Are you asking if the number was previously rounded? Do you mean a whole number? Even?

    I look forward to your reply.
    Alex G.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by nikolaalx View Post
      Hi,
      I am trying to calculate the current price in order to see if it is a round number....but can't seem to figure out a way to do it.

      I am thinking of dividing Close[0] by a variable and then verifying if it is an integer.


      {Close[0] / 50 = var1;}

      And then to check if Var1 == whole number


      Any input would be greatly appreciated.

      Thanks.
      if ((Close[0] - (int)Close[0]) == 0) {//Close[0] is a whole number, with no fractional part that is not also zero.}

      Comment


        #4
        I apologize if it was a bit unclear, but my mother tongue is not English.

        It would be easier to give an example.

        I want to be able to tell if the price is a multiple of a given number. My goal is to be able to identify key price action levels.

        E.g. if I set my multiple to be 50, then if Close[0] is 2000, 2050, 2100, 2150 to have my signal.

        Original Idea was to divide the closing price by the multiple, and then to see if the output is an integer.

        E.g. if Close[0] is 2000, then to divide it by 50 and the result would be 40.

        If the Close[0] is 2001, dividing it by 50 would not result in an integer but rather a double digit.




        Originally posted by NinjaTrader_AlexG View Post
        Hello,
        Thanks for posting today.

        Can you give a little clarification of what you mean by a round number? Are you asking if the number was previously rounded? Do you mean a whole number? Even?

        I look forward to your reply.
        Last edited by nikolaalx; 06-22-2015, 03:24 PM.

        Comment


          #5
          Hello nikolaalx,
          Thanks for the reply.

          You can use the modulus operator (%) to determine if a number is divisible by the divisor.

          If for example you did
          Print(5000 % 50); //output would be 0 since 50 goes into 5000 evenly without a remainder.

          So if you did
          if (Close[0]% 50 !=0 )

          then the number has a remainder.

          Please let us know if we may be of further assistance for anything NinjaTrader.
          Alex G.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Hwop38, 05-04-2026, 07:02 PM
          0 responses
          152 views
          0 likes
          Last Post Hwop38
          by Hwop38
           
          Started by CaptainJack, 04-24-2026, 11:07 PM
          0 responses
          305 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
          345 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by M4ndoo, 04-19-2026, 05:54 PM
          0 responses
          176 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Working...
          X