Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Rounding question

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

    Rounding question

    I need to round up to specify a price for long entry and round down to specify a price for short entry. As an example, let's say a bar has a low of 5 and a high of 10. I key off the mid-point, which is 7.5.

    If this was an up bar (green candle) it would be part of a long setup and I want to submit a limit order to buy at the mid-point, but in this case the instrument trades in whole ticks, so I need to submit at the nearest whole tick ABOVE the midpoint, which is 8.

    The concept is reversed for a short where the bar is down (or red candle) so the required valued is 6.

    I'm familiar with MasterInstrument.Round2TickSize(), but I don't think I can count on this round according to my requirements. So, how would I go about doing this?

    #2
    plus 0.5 for long and -0.5 for short

    Comment


      #3
      Hi Baruch,

      I had to think through your answer for a moment, at first contemplating how to explain to you why this wont work (for example when the bar size in ticks is even, as opposed to the odd example above).

      Then I realized I could calculate the mid-point, run it through an IF, testing if the mid-point is fractional or not, then doing what you suggest when it's fractional.

      Is this what you had in mind? Or am I being really dunce here and missing something simple?

      Comment


        #4
        Originally posted by coolmoss View Post
        I need to round up to specify a price for long entry and round down to specify a price for short entry. As an example, let's say a bar has a low of 5 and a high of 10. I key off the mid-point, which is 7.5.

        If this was an up bar (green candle) it would be part of a long setup and I want to submit a limit order to buy at the mid-point, but in this case the instrument trades in whole ticks, so I need to submit at the nearest whole tick ABOVE the midpoint, which is 8.

        The concept is reversed for a short where the bar is down (or red candle) so the required valued is 6.

        I'm familiar with MasterInstrument.Round2TickSize(), but I don't think I can count on this round according to my requirements. So, how would I go about doing this?
        Math.Ceiling(calculatedValue) for Long and Math.Floor(calculatedValue) for Short.
        Last edited by koganam; 09-02-2013, 06:20 AM. Reason: Corrected capitalization

        Comment


          #5
          Hello coolmoss,

          Thank you for your post.

          Great question here on this item and great information from koganam on the Math.Ceiling and Math.Floor C# methods. While these are C# methods, NinjaScript is based on C# and you can use methods outside of the set NinjaScript methods and functions in the Help Guide.

          Links to the Math.Ceiling and Math.Floor methods can be found below:

          Comment


            #6
            You don't need "if", yust add or substract.
            The only problem will be that X.5 will be rounded up..
            If for shorts you need it to be rounded down, then make it Y-0.50001

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            670 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            379 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            111 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            575 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            582 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X