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

Rounding to tick...

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

    Rounding to tick...

    Who would have thought it would be such a task!
    I have seen many convoluted ways to do it and it seemed none were satisfactory, here is a simple statement that works for me.

    RoundedValue = Math.Round(RawValue/TickSize) * TickSize

    If you need to "Tick up" or "Tick down" substitute Math.Floor or Math.Ceiling.
    Last edited by Sleeping Troll; 05-04-2010, 07:36 PM.

    #2
    Originally posted by Sleeping Troll View Post
    Who would have thought it would be such a task!
    I have seen many convoluted ways to do it and it seemed none were satisfactory, here is a simple statement that works for me.

    RoundedValue = Math.Round(RawValue/TickSize) * TickSize

    If you need to "Tick up" or "Tick down" substitute Math.Floor or Math.Ceiling.
    I'm new to programing and this is something I've been jotting down to get done . . . say i have a value that will be generated on ES (tick size is 0.25) of 1188.67 (which would round to 1188.75) from a dataseries called AverageValue , how exactly would the code text appear?

    Say I wanted to round it to the nearest point (4ticks per point so 1188.67 would actually round to 1189), how would that code text appear?

    Comment


      #3
      I'm new to programing and this is something I've been jotting down to get done . . . say i have a value that will be generated on ES (tick size is 0.25) of 1188.67 (which would round to 1188.75) from a dataseries called AverageValue , how exactly would the code text appear?

      MyValue = Math.Round(AverageValue/TickSize) * TickSize;

      Say I wanted to round it to the nearest point (4ticks per point so 1188.67 would actually round to 1189), how would that code text appear?

      MyValue = Math.Round(AverageValue);

      Comment


        #4
        Thank you, so if I wanted to round to the nearest 2 ticks it would be:

        MyValue = Math.Round(AverageValue/(TickSize*2)) * TickSize * 2?

        I think that is correct . . .

        Originally posted by Sleeping Troll View Post
        I'm new to programing and this is something I've been jotting down to get done . . . say i have a value that will be generated on ES (tick size is 0.25) of 1188.67 (which would round to 1188.75) from a dataseries called AverageValue , how exactly would the code text appear?

        MyValue = Math.Round(AverageValue/TickSize) * TickSize;

        Say I wanted to round it to the nearest point (4ticks per point so 1188.67 would actually round to 1189), how would that code text appear?

        MyValue = Math.Round(AverageValue);
        Last edited by Insearch; 05-04-2010, 08:55 PM.

        Comment


          #5
          Just for the sake of your sanity, it is always best to use parentheticals even though it would seem they are not needed.

          MyValue = Math.Round(AverageValue/(TickSize*2)) * (TickSize * 2);

          It would even be a good idea to assign your round value...

          Ticks = (TickSize * 2);
          MyValue = Math.Round(AverageValue/Ticks) * Ticks;
          Last edited by Sleeping Troll; 05-04-2010, 09:18 PM.

          Comment


            #6
            Thanks a lot. Yeah, I do/did a lot of logic modeling in excel and always used paranthesis for what I wanted to "block out" as separate calculations when there were several levels of logic involved . . .

            Thank You also for the tip, I'm no programmer but that "assigning" tip is really helpful in more ways that you can imagine . . ., well at least for me . . .


            Originally posted by Sleeping Troll View Post
            Just for the sake of your sanity, it is always best to use parentheticals even though it would seem they are not needed.

            MyValue = Math.Round(AverageValue/(TickSize*2)) * (TickSize * 2);

            It would even be a good idea to assign your round value...

            Ticks = (TickSize * 2);
            MyValue = Math.Round(AverageValue/Ticks) * Ticks;

            Comment


              #7
              Thanks for sharing your solutions - not sure if you guys were aware, but there's also a NinjaScript function for this -

              BertrandNinjaTrader Customer Service

              Comment


                #8
                Thanks Bert! Was just looking for that!
                Last edited by mountainclimber; 05-07-2010, 10:27 AM.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by mangel2000, Today, 02:23 AM
                0 responses
                2 views
                0 likes
                Last Post mangel2000  
                Started by mangel2000, Today, 01:30 AM
                0 responses
                8 views
                0 likes
                Last Post mangel2000  
                Started by Doxxxx, Today, 01:24 AM
                0 responses
                5 views
                0 likes
                Last Post Doxxxx
                by Doxxxx
                 
                Started by ezekilany, Today, 01:10 AM
                0 responses
                4 views
                0 likes
                Last Post ezekilany  
                Started by usjavaburn, Today, 12:59 AM
                0 responses
                3 views
                0 likes
                Last Post usjavaburn  
                Working...
                X