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

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 judysamnt7, 03-13-2023, 09:11 AM
          4 responses
          59 views
          0 likes
          Last Post DynamicTest  
          Started by ScottWalsh, Today, 06:52 PM
          4 responses
          36 views
          0 likes
          Last Post ScottWalsh  
          Started by olisav57, Today, 07:39 PM
          0 responses
          7 views
          0 likes
          Last Post olisav57  
          Started by trilliantrader, Today, 03:01 PM
          2 responses
          22 views
          0 likes
          Last Post helpwanted  
          Started by cre8able, Today, 07:24 PM
          0 responses
          10 views
          0 likes
          Last Post cre8able  
          Working...
          X