• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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 digibob, Today, 01:13 AM
          0 responses
          2 views
          0 likes
          Last Post digibob
          by digibob
           
          Started by kemoleena, Today, 12:31 AM
          0 responses
          5 views
          0 likes
          Last Post kemoleena  
          Started by aligator, 09-18-2019, 12:15 PM
          12 responses
          104 views
          0 likes
          Last Post Lancer
          by Lancer
           
          Started by StevenNelson, Yesterday, 05:45 PM
          0 responses
          7 views
          0 likes
          Last Post StevenNelson  
          Started by calebsandfort, Yesterday, 05:16 PM
          1 response
          7 views
          0 likes
          Last Post calebsandfort  
          Working...
          X