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 Aviram Y, Today, 05:29 AM
          0 responses
          2 views
          0 likes
          Last Post Aviram Y  
          Started by quantismo, 04-17-2024, 05:13 PM
          3 responses
          25 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by ScottWalsh, 04-16-2024, 04:29 PM
          7 responses
          34 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by cls71, Today, 04:45 AM
          0 responses
          6 views
          0 likes
          Last Post cls71
          by cls71
           
          Started by mjairg, 07-20-2023, 11:57 PM
          3 responses
          217 views
          1 like
          Last Post PaulMohn  
          Working...
          X