Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Cancelling Target Orders when Stops are filled/Overfill/OCO handling

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

    Cancelling Target Orders when Stops are filled/Overfill/OCO handling

    Hello,

    I'm receiving this message in the log/output window
    http://screencast.com/t/MxKpUFnVM

    Is it preferable to allow the Internal Order Handling to cancel this target order as shown once the corresponding stop is hit? Or should I make a specific section of code to cancel these orders before the IOrder sequence gets to this point?

    The reason I'm asking is that I'll be attempting to code Overfill error avoidance in my strat. Any help is appreciated since I'll need to know where it is best to cancel or read the orderstate: i.e. OnOrderUpdate or OnExecution.

    Thanks,
    Kirk

    #2
    zeller4,

    I am happy to assist you.

    Is it preferable to allow the Internal Order Handling to cancel this target order as shown once the corresponding stop is hit? Or should I make a specific section of code to cancel these orders before the IOrder sequence gets to this point?
    This is a personal preference. It really depends on what you are willing to accept, and your conditions for the orders. In other words, maybe you have some condition where you would like to cancel the order before hand. Internal order handling is coded to basically try to prevent overfills, etc. The unmanaged approach offers you more control, but then you need to build in your own safeties as it suites you.

    The reason I'm asking is that I'll be attempting to code Overfill error avoidance in my strat. Any help is appreciated since I'll need to know where it is best to cancel or read the orderstate: i.e. OnOrderUpdate or OnExecution.
    OnOrderUpdate() updates when any order is submitted, pending, etc. OnExecution only occurs when an order is filled.

    Please let me know if I may assist further.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Hello,

      If I have a long position on and I have a target price and a stop price in. How can I then cancel the stop price if my target price is filled ?

      Put another way can a stop be placed in conjuction with OCO ? And how do I use the OCO function? I am not using a script, these are manually entered.

      Thanks

      Comment


        #4
        Originally posted by mcorbett View Post
        Hello,

        If I have a long position on and I have a target price and a stop price in. How can I then cancel the stop price if my target price is filled ?

        Put another way can a stop be placed in conjuction with OCO ? And how do I use the OCO function? I am not using a script, these are manually entered.

        Thanks
        You can use ATM strategies for this. Are these manual orders?

        Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_AdamP View Post
          You can use ATM strategies for this. Are these manual orders?

          http://www.youtube.com/watch?v=kIHBYC15luc
          Yes, I would have bought and then put in stop and target, if either stop or target get fills I want to cancel one or otehr depending which one gets filled fist...

          thanks

          Comment


            #6
            mcorbett,

            Thanks for your note.

            If you right click in the Chart trader or Dom before you place your stop and target, you can enable OCO, then place your orders, then right click again and uncheck OCO.

            Otherwise, please watch the video I have provided as it will allow you to create a ATM strategy that does this as well, however automated.

            Please let me know if I may assist further.
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              Hi,

              Is it possible to just use the field in the control center labeled OCO?

              Thanks

              Comment


                #8
                mcorbett,

                Here is our OCO documentation :



                You can use OCO in chart trader and the superdom.
                Adam P.NinjaTrader Customer Service

                Comment


                  #9
                  Thank you.

                  I read it.

                  However why is there an OCO field in the control center window?

                  I was thinking there is an easy manula way to link orders, the OCO function as it stands is really just for intraday trades...

                  Comment


                    #10
                    mcorbett,

                    If you are referring to the orders tab in the control center, this is just giving you the OCO ID so you can see which trades are grouped in OCO.

                    Please let me know if I may assist further.
                    Adam P.NinjaTrader Customer Service

                    Comment


                      #11
                      I see a blank space on the orders tab named "OCO".

                      It appears to be a place where I can input an order "ID" or token.

                      Example, I were to put in a stop I could also include an "ID" here that would link it to the limit order. So if stop is hit limit would cancel..... sort of manual

                      The tutorial is unclear... no idea what its trying to do

                      Comment


                        #12
                        mcorbett,

                        ID's are generated by ninjatrader whenever you place an OCO order, there is no way to set them in the control center.

                        OCO is enabled or disabled manually in the SuperDOM or ChartTrader. We have a video that covers how to do it.

                        Download NinjaTrader FREE at http://www.ninjatrader.comThis video is a recording of our live "Charting Level 1" webinar covering the topics:Creating a chartC...
                        Adam P.NinjaTrader Customer Service

                        Comment


                          #13
                          Code to simulate Overfill

                          Hello,

                          I've developed a small script based on SampleCancelOrder so that I could learn how to avoid errors with Overfills.

                          Here is a screenshot of the error message:

                          http://screencast.com/t/1bDpZKpo

                          I placed this code in the OnOrderUpdate to attempt to force an Overfill error.

                          Code:
                          if (order.OrderState == OrderState.PendingCancel)
                          {
                          	Print("26 - order.OrderState == OrderState.PendingCancel: "+DateTime.Now.ToString());
                          	//placed here on purpose to force an Overfill condition
                          	CancelOrder(entryOrder);
                          	Print("26 ==================================");
                          }
                          I'm trying to observe if this produces an overfill every time... I don't think it does yet (still testing).
                          Am I right in assuming the PendingCancel within OnOrderUpdate is the main area where overfill problems will surface? Or can they surface in OnExecution as well?
                          Thanks,
                          kz
                          Attached Files
                          Last edited by zeller4; 02-16-2012, 02:51 PM.

                          Comment


                            #14
                            Hi zeller4,

                            There's no specific handler used for generating overfills. Overfill is when an order is marked for cancellation and then filled. It can also happen when the strategy has competing orders sent at the same time, when only one should be filled. The main area where they will occur is with orders resting close near the market and cancel is sent for any reason: One pair of OCO is filled, position set to opened in opposite direction, autoexpirations, or you send CancelOrder().

                            I don't think you'll be able to reproduce an overfill on simulated account like you're doing. For an overfill the order must be filled in-between pending cancel and cancel. Unfortunately we do not have a strategy to provide you that will produce overfills on demand.
                            Last edited by NinjaTrader_RyanM1; 02-16-2012, 04:35 PM.
                            Ryan M.NinjaTrader Customer Service

                            Comment


                              #15
                              Thanks for the explanation. My only reason for "mis-coding" to achieve an overfill was so that I can learn how to prevent them. The sample or code snippet of the method of checking a "resting-near-the-market" order would be beneficial.

                              Also, what do you mean by
                              competing orders sent at the same time, when only should be filled.
                              If I understand the OCO part, once the stop is filled, the target is filled because they have the identical naming string from EntrySignal.

                              My purpose of creating the indi was to get a better understanding from the print statements how the Internal Orders are processed in OnOrderUpdate vs. OnExecution.

                              Also, is there any validity to the following? Or will it never occur? (I'm trying to understand
                              why (or if) a fill state would have to be checked for something that is cancelled.)
                              Code:
                              if (entryOrder_1a != null && entryOrder_1a == execution.Order)
                              {
                              if (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled == 0)
                              {//print or do something...
                              }
                              }
                              Last edited by zeller4; 02-16-2012, 04:55 PM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Tim-c, Today, 02:10 PM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by Taddypole, Today, 02:47 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post Taddypole  
                              Started by chbruno, 04-24-2024, 04:10 PM
                              4 responses
                              50 views
                              0 likes
                              Last Post chbruno
                              by chbruno
                               
                              Started by TraderG23, 12-08-2023, 07:56 AM
                              10 responses
                              399 views
                              1 like
                              Last Post beobast
                              by beobast
                               
                              Started by lorem, Yesterday, 09:18 AM
                              5 responses
                              25 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X