Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

unmanaged/partial fills anc changeorder

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

    unmanaged/partial fills anc changeorder

    Hi,
    I am having some issues with the unmanaged orders. I am missing something.
    Example:
    My strategy sumbits a long order for let's say 100 contracts.
    20 contracts get filled.
    In onexecution I get a partfilled status and submit a stop loss and profit target order with 20 on each.
    40 contracts get filled.
    In onexecution I get a partfilled status and submit a stop loss and profit target order with 40 on each.
    25 contracts get filled.
    In onexecution I get a partfilled status and submit a stop loss and profit target order with 25 on each.
    10 contracts get filled.
    In onexecution I get a partfilled status and submit a stop loss and profit target order with 10 on each.
    1 contracts get filled.
    In onexecution I get a partfilled status and submit a stop loss and profit target order with 1 on each.
    1 contracts get filled.
    In onexecution I get a partfilled status and submit a stop loss and profit target order with 1 on each.
    1 contracts get filled.
    In onexecution I get a partfilled status and submit a stop loss and profit target order with 1 on each.
    1 contracts get filled.
    In onexecution I get a partfilled status and submit a stop loss and profit target order with 1 on each.
    1 contracts get filled.
    In onexecution I get a partfilled status and submit a stop loss and profit target order with 1 on each.

    within onbarupdate:
    My strategy hits certain measurments and I decide I want to move stop losses to break even so I run:
    ChangeOrder(SomeStopLossOrder, Position.Quantity, 0, MyChangeToPrice);

    It seems Position.Quantity varies, sometimes being 100 or anywhere in between.
    What I think I am missing is that I need to create an array of iOrders, something like SomeStopLossOrder[5] so that when I am doing a ChangeOrder it would look like:
    loop through count of SomeStopLossOrder
    ChangeOrder(SomeStopLossOrder[i], Position.Quantity, 0, MyChangeToPrice);
    If this is the correct method to attack this then I would also have to have something that tracks the quantity partially filled that is associated with each SomeStopLossOrder[i].

    Am I understanding this correctly? There certainly aren't much in depth examples using the unmanaged approach.

    Thanks

    #2
    trtrav,

    There is not a complete sample available, as it's designed for programmers already familiar with our advanced framework. The property you may be looking for here is execution.Order.Filled.

    This is the total cumulative filled from a specific Order object.

    To see the types of values you can expose from an execution event, try Printing these two:

    Print(execution.Order.ToString());
    Print(execution.ToString());

    Last edited by NinjaTrader_RyanM1; 08-09-2011, 10:34 AM.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      When I use execution.Order.Filled for submitting stop loss and profit target orders within OnExecution, I get all the trade quantities correct except the last fill which ends up being the total filled. I use execution.Quantity instead and it works fine.

      The issue is when I go to change and order to break even. I use ChangeOrder on the stop loss iOrder object. Which quantity should I use for that and if it references the iOrder object which of the partial fills does it end up changing?

      Comment


        #4
        You only have one order object, even if that object is filled partially multiple times.

        If you want ChangeOrder() on a stop loss to reflect the total filled from an entry, can use execution.Order.Filled, from the execution event.

        Position.Quantity should be what you're looking for as well. Can you show us your usage so we have an idea why it doesn't match the actual position quantity?

        Best is to print everything you can, and monitor output for these values during partial fill cases.

        This sample does not use unmanaged approach, but can be a good introduction to working with these advanced handlers and IOrders:
        The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()


        You should be familiar with all the types of values you can access before trying to do the same type of strategy using unmanaged approach.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Thanks for the help. What I was doing was overwriting the iOrder object with additional stop loss and profit target orders on every partial fill. I changed it so that if the iOrder object was not null to do a changeorder. Looking back it was pretty stupid what I was doing, but I can see how some strategies would never be affected by the bug I had created.

          Now, when I do a changeorder to move to break even there is only 1 order as there should be.

          Comment


            #6
            OK, glad to hear you tracked it down. Thanks for updating us with the solution.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              ChangeOrder quantity

              if I want to change:

              1) target order linked with stop order by OCO and
              2) target order is partially filled

              what should I use:

              1) ChangeOrder(targetOrder, targetOrder.Quantity, Close[0], targetOrder.StopPrice);
              or
              2) ChangeOrder(targetOrder, targetOrder.Quantity - targetOrder.Filled, Close[0], targetOrder.StopPrice);

              I'm not sure what quantity Is should use. Of course I want keep OCO link with right quantities.
              Last edited by marekj; 12-11-2012, 09:55 PM.

              Comment


                #8
                Where do you issue the ChangeOrder command? In OnExecution()? The second variant would be needed to keep the scenario of a partial fill in mind.

                Comment


                  #9
                  I'm amending order using ChangeOrder from OnBarUpdate.

                  For quantity, should I use

                  1) targetOrder.Quantity - targetOrder.Filled (as you recommended) or
                  2) Position.Quantity or
                  3) doesn't matter, both will work for the case I described?

                  Comment

                  Latest Posts

                  Collapse

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