Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Addon : Partially close a position

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

    Addon : Partially close a position

    Hi dear coders and traders;

    I have a small issue currently : I'd like to partially close positions when some conditions are completed.
    The user may choose oh many % of the position will be close.
    For some instruments, it's working but for some other, no.

    Is there is a small trick please to round the new quantity (after dividing the position size) to the right format of the instrument quantity sizing?

    Regards

    #2
    Note that guys, It's an addon, not based on the Strategy object

    Comment


      #3
      Hello NeimadTWC,

      Thank you for your post.

      Quantities need to be an int value, so you could round down after doing a division.

      Code:
      int newQuantity = Convert.ToInt32(Math.Floor(yourValue));
      Please note that you will want to make sure that the calculated value makes sense in regard to the overall position, and doesn't leave a partially open position or exceed the position quantity.

      For example, if the position quantity was 3 and you divide by 2 the calculate value will be 1.5. Rounding down, the new value would be 1 which is less than half and leaves 2 quantity open.

      Additionally, if you are using forex instruments you will also have to make sure that the calculated quantity is a valid lot size based on what your broker accepts for forex quantities.

      Please let us know if you have any other questions.

      Comment


        #4
        Hi Gaby;

        Thanks a lot for your answer. Yes so Math.Foor may help, here I "wanted" to know if there is something as information that provides lot-step for instrument, as there is that kind of info for tick-size and also a method to round the price properly for each instrument.

        Comment


          #5
          Hello,

          You can use TickSize to access tick size info for the instrument.

          TickSize - https://ninjatrader.com/support/help...8/ticksize.htm

          To round the price properly for each instrument, use RoundToTickSize().

          RoundToTickSize() - https://ninjatrader.com/support/help...toticksize.htm

          There is no way to access information on the lot size per instrument unfortunately.

          As mentioned, lot size for forex instruments varies by broker. You will want to reach out to your broker for valid forex quantities.

          Please let me know if you have any other questions.

          Comment


            #6
            Thanks Gaby, I will for sure in case I need

            Comment

            Latest Posts

            Collapse

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