Announcement

Collapse
No announcement yet.

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 -

              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 Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                579 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                334 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                101 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                554 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                551 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X