Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OCO to Market Order

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

    #16
    Thanks Brett, this helps me design exit strategy without an over fill.
    Is it possible to enter the limit order for entry and convert it to market without getting over fill status?
    Initial entry statement : EnterLongLimit(10, 1430, “LE”) and then after getting a partial fill from “LE” order, I would like to issue below statement
    EnterLongLimit(GetCurrentAsk()+2*ticksize,“LE”) // expecting this statement will modify the existing “LE” order in the exchange
    Will this sequence of steps issues any cancel order? What happens if the quantity 10 gets executed in exchange before the second statement reaches the exchange? Is there any chance of getting over fill status?
    Thanks,
    gsreddy

    Comment


      #17
      Hello,

      The modification would not send a cancel it would directly modify the order to fill. This is the best approach for no overfill.

      You could cancel the order, then wait for it to be cancelled and then submit the market to also have no overfill but if you do this you would lose time to wait for the order to cancel and resubmit.

      If the order qty gets filled however and there is a millisecond time where if NT isnt aware of the changed QTY before it modifies the order you could have an over fill your strategy would notify you immediately and attempt to terminate if this was to ever occur.

      -Brett
      BrettNinjaTrader Product Management

      Comment


        #18
        thanks Brett for the reply,

        if I understand correctly, even by submitting the request to modify existing entry order in the exchange, there is a chance of getting over fill. If we get the over fill strategy will get stopped in managed approach and there is no way to programmatically handle over fill in managed approach. I love to use the managed approach but it will not fit for my design because of over fill.
        Please correct me if I am wrong. Can you please point me to any help full examples /threads related to unmanaged approach?

        Thanks,
        gsreddy.

        Comment


          #19
          Hello,

          Sure to further explain the chance for this type of overfill can happen in managed or unmanaged. The only way to guarantee it to not happen is to cancel the profit target wait for confirmation it is cancelled and then submit the exit.

          You can do this in either the unmanaged or managed approach.

          However if you switch to unmanaged what you gain is the ability to handle the overfill situation is one was to occur with your own custom handling.

          Information on the unmanaged approach can be found here:



          and to disable the NT overfill handling:



          -Brett
          BrettNinjaTrader Product Management

          Comment


            #20
            Hi Brett,

            Thanks for all your quick replies and providing the valuable information and making me understand managed approach. Even if we issue cancel order for unfilled entry order quantity, that can cause the overfill, if we have any in flight change.

            Can you please help me with the examples related to below process using unmanaged approach where we have control over overfilles?

            The code in the onbarupdate will set the below variables in my code.
            v_goFlat, v_goLong, v_ goShort, v_entryprice, v_ profittargetprice, v_stopprice. I have completed the coding and tested setting the above order entry variables.
            Can you please point me to an example code which covers most of below order entry process with unmanaged approach?
            1) Enter the limit order for initial entry based on flags and entry price.
            2) For every fill issue the OCO order for PT and STOP
            3) If the price trades 50 ticks after touching the entry price convert the entry limit orders to market order by modifying the entry limit order
            4) If there is any overfill, generate the OCO order for PT and STOP for the over fill quantity.
            5) If the market conditions change and need to increase the PT, modify the PT leg in OCO orders
            6) If the market conditions changes and need to close the position, modify the stop leg in the OCO orders
            7) If there is any order rejections or unexpected error, revalidate the OPEN position and orders in the exchange. Cancel the orders in the exchange and reissue the orders for the condition that caused the order rejection or error.
            8) At this point of time to keep it simple i would like to have one quantity per lot with 10 lots. So for every lot we will be issuing one entry order. With this approach each lot will be handled separately and if there is any un expected behavior (over fill, rejection, error) , just need to handle one single lot that caused the issue.

            Can you please pint me to helpful example code for the above approach?

            Thanks
            gsreddy.

            Comment


              #21
              Hello,

              Unfortunately I do not have any un-managed code examples other then what is in the help guide.

              You would use OnOrderUpdate() and OnExecution() for most of your custom handling with unmanaged approach.

              These samples would show you how to do that:

              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()


              All of our samples here:

              Following are links to all available NinjaScript reference samples within this forum section: Strategy Reference Samples (NinjaTrader 8) - also applicable to NT7 Using a time filter to limit trading hours (http://www.ninjatrader.com/support/forum/showthread.php?t=3226) Using multiple entry/exit signals simultaneously


              -Brett
              BrettNinjaTrader Product Management

              Comment


                #22
                Thanks berett,
                Before I get into the coding, I need to understand the unmanaged approach process completely. With the below process design in the previous post(step 3), I do see most of the time I will get over fill or order rejects(50% chance).
                I will get back to you with the list of questions for clarifications before I start coding.
                Your response is so quick and timely, keeping me think all the time for all possible cases.
                Thanks
                gsreddy

                Comment


                  #23
                  Hi,
                  I am trying to understand the IOrder object OrderState property. It will be great if you can clarify below questions along with the below example process.

                  With the unmanaged approach, strategy prevents internal signal tracking and internal order handling rules. Is this correct?
                  Can you please suggest the best place to submit the profit target and stop loss orders and explain why you think that is the best method to submit PT and Stop loss orders?

                  Example process: we have a working order in the exchange with quantity 20 submitted from ninja strategy using unmanaged approach and gets below partial fills to fill the total quantity and an over fill, can I expect below IOrder object properties in onOrderUpdate and iexecution object properties in OnExecution methods? Correct me if I am wrong.

                  Fill 1: market has filled 2 out of 20.
                  Broker Account will have 2 filled quantity and working order for 18 in the exchange
                  At what point of time strategy quantity will get updated with this partial fill 2 quantity?

                  As soon as 2 quantity gets filled in the exchange, I am expecting below sequence of calls will get executed in the order in the strategy.

                  Call 1: OnOrderUpdate(IOrder order) method will get called with below IOrder object properties.
                  order .OrderState == OrderState.PartFilled
                  order. Filled == 2
                  order. Quantity == 20
                  order. OverFill == False

                  Call 2: After the OnOrderUpdate call, strategy will call OnExecution(IExecution execution) method
                  Case 1: assuming No fill (in flight) between Call 1 and Call 2
                  execution.Order.OrderState == OrderState.PartFilled
                  execution. order. Filled == 2
                  execution. order. Quantity == 20
                  execution. Quantity == 2
                  execution. order. OverFill == False
                  Case2: assuming 3 more quantity got filled between call 1 and call 2 or during the execution of Call 1 (In Flight Fill)
                  execution.Order.OrderState == OrderState.PartFilled
                  execution. order. Filled == 5 (2 + 3) ??
                  execution. order. Quantity == 20
                  execution. Quantity == 5 ( is this correct ??)
                  execution. order. OverFill == False

                  at what point of time OnOderUpdate will be called for this 3 quantity? Are there any important properties that I am missing other than price related?

                  Assuming market has filled 16 quantities during the process and left with final 4 quantity.

                  Final Fill : remaining 4 quantity got filled ( total order quantity got filled)
                  Call 11: OnOrderUpdate(IOrder order) method will get called with below IOrder object properties.
                  order .OrderState == OrderState.PartFilled ( is this OrderState.PartFilled or OrderState.Filled ?)
                  order. Filled == 20 ( is this 4 or 20?)
                  order. Quantity == 20
                  order. OverFill == False
                  Call 22: After the OnOrderUpdate call, strategy will call OnExecution(IExecution execution) method
                  execution.Order.OrderState == OrderState.PartFilled
                  execution. order. Filled == 20
                  execution. order. Quantity == 20
                  execution. Quantity == 4
                  execution. order. OverFill == False

                  do I need to compare order. Filled with order. Quantity to check whether the complete order quantity got filled or not in OnOrderUpdate or in OnExecition methds?

                  Assuming quantity 5 got filled instead of remaining 4 quantity ( Over Fill case)
                  Call 111: OnOrderUpdate(IOrder order) method will get called with below IOrder object properties.
                  order .OrderState == OrderState.PartFilled
                  order. Filled == 21
                  order. Quantity == 20
                  order. OverFill == True
                  Call 222: After the OnOrderUpdate call, strategy will call OnExecution(IExecution execution) method
                  execution.Order.OrderState == OrderState.PartFilled
                  execution. order. Filled == 21
                  execution. order. Quantity == 20
                  execution. Quantity == 5
                  execution. order. OverFill == False

                  sorry for the long list of questions, I am trying to understand the execution process before I design and code order executions in my strategy.

                  Thanks
                  gsreddy.
                  Last edited by gsreddy; 09-14-2012, 12:23 AM.

                  Comment


                    #24
                    Hello,

                    1) The best way to do submit stop loss and profit targets are shown in this sample:
                    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()


                    2) You would get OrderUpdates() for each partial fill, so you can submit order for the partial fill to protect it and modify it to larger when you have more get filled or you go to fully filled state. The sample above shows how to do this.

                    3) The only problem with your example is that you list Order.OverFill. If you turn off OrderFill handling with the unmanaged then these would not longer matter you would need to do your own order fill detection but other then that I think you have the general idea of what to do.


                    -Brett
                    BrettNinjaTrader Product Management

                    Comment


                      #25
                      Hi Brett,
                      Thanks for quick response. Can you please conform the object properties for the blow example in the post #23. Are they correct for Fill1-> Call2-> Case2 and FinalFill?
                      it will be great if you can edit and provide all the object property values in that example as it will cover most or all of the cases that i need to handle in my design.

                      do I need to compare “order. Filled” with “order. Quantity” to check whether the complete order quantity got filled or not in OnOrderUpdate or in OnExecition methds?

                      If I tie Limit and Stop orders as OCO order by passing ocoId to SubmitOrder and if I cancel one of the order (Limit order), is ninja going to cancel the other order or do I need to cancel both the orders?

                      Thanks
                      gsreddy
                      Last edited by gsreddy; 09-14-2012, 11:02 AM.

                      Comment


                        #26
                        Hello,

                        Yes you looked like you were on the right track and everything looked good at first glance. Of course until you actually get in there and start programming will everything be fully fleshed out.

                        You can compare the .Filled vs .Quantity but it is not needed as you can just chekc OrderState. If OrderState= PartFill then it is a part fill and OrderState will only go to Filled when the entire order is filled so .Filled = .quantity.


                        NinjaTrader will cancel all orders with the OCO ID that is submitted when one order gets filled or cancelled this is an action of the NinjaTrader core order handling.

                        -Brett
                        BrettNinjaTrader Product Management

                        Comment


                          #27
                          Thans Bertt, If you provide all the property values in the below example, It will boost the time required to complete my strategy as I am moving from managed approach to unmanaged approach and don’t need to build any sample strategy for testing the order behavior at different levels.
                          I know it is big post, but it will cover all the things I need. If you can provide the property values as you red, it will tack couple of more minutes than reading it.
                          Thanks
                          gsreddy

                          Comment


                            #28
                            Hello,

                            Not sure what you are asking exactly. If you have an exact question I can answer it however I wouldn't be able to write a sample that directly addresses your question. You would need to code it and then if you had any unexpected output let me know I can help you look into it and answer questions.

                            -Brett
                            BrettNinjaTrader Product Management

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by sjsj2732, Yesterday, 04:31 AM
                            0 responses
                            36 views
                            0 likes
                            Last Post sjsj2732  
                            Started by NullPointStrategies, 03-13-2026, 05:17 AM
                            0 responses
                            287 views
                            0 likes
                            Last Post NullPointStrategies  
                            Started by argusthome, 03-08-2026, 10:06 AM
                            0 responses
                            287 views
                            0 likes
                            Last Post argusthome  
                            Started by NabilKhattabi, 03-06-2026, 11:18 AM
                            0 responses
                            133 views
                            1 like
                            Last Post NabilKhattabi  
                            Started by Deep42, 03-06-2026, 12:28 AM
                            0 responses
                            95 views
                            0 likes
                            Last Post Deep42
                            by Deep42
                             
                            Working...
                            X