Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order rejection compound leg, concurrent action

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

    Order rejection compound leg, concurrent action

    Hi guys,
    can you tell me what circumstances might lead to the following rejected order?

    ninja continuum, Cannot use compound leg because of concurrent action. Please try again later. Failed to persist order to db, there was attempt to use an inactive order in a compound order affected Order: BuyToCover 1 Stop @ 155.3125

    Thanks,
    saltminer

    #2
    Hello saltminer,

    This rejection error happens when an automated strategy places OCO orders at the same time and the CQG OCO system is not prepared to accept the concurrent order. As listed in the CQG disclaimer, there is a 250ms delay when using server side OCO. In order to account for this, you can use the two workarounds below.

    1) Switch to local OCO simulation managed by the local NinjaTrader instance. You can switch as follows. Go to Control Center-->Tools-->Account Connections, highlight your connection and click Edit. Click Next twice and enable 'Local OCO simulation'. Click Next until you finish the connection. Restart NinjaTrader.

    2) Program the strategy to account for the 250ms delay by waiting for the first leg of the order to be accepted by CQG before placing the second.
    JasonNinjaTrader Customer Service

    Comment


      #3
      Hi,
      I've coded such that the state of "Accepted" or "Working" must be received by the first leg of an OCO pair before the second leg is submitted.
      However, this still causes problems.

      An exit bracket has two orders, Ex0 and TS0.

      The code correctly waited for order Ex0 on ZN 12-14 to reach the state of “Accepted”, and submitted its paired order TS0.
      Problem was, while TS0 was on the road, Ex0 got filled. So by the time the OCO order got to the broker the original order had been filled, which meant that TS0 got rejected.

      I don’t know how to get around this problem. Obviously at any stage an order can get filled; there is no “safe” time to submit a paired OCO order for one that is already working in the market. Waiting x milliseconds doesn’t solve anything, as you could wait x milliseconds, all clear, submit the order and still find that the first order of the pair gets filled while you’re doing it.

      Am I missing something? What is the recommend programming technique for this?

      Many thanks,
      saltminer

      Comment


        #4
        Hi saltminer,

        Using Local OCO may correct this issue for you.

        Tools -> Account Connections -> select the connection -> click the Change button
        Click next twice -> check the Local OCO box -> click Next until Finish
        Then disconnect from your connection and reconnect
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi,
          yes, but we are endeavouring to NOT use local OCO.
          Please refer to my previous post for info to answer "What is the recommend programming technique for this?"

          Many thanks,
          saltminer

          Comment


            #6
            Hi saltminer,

            To correct this issue in code, you could change your code to not stop on rejections, detect the rejection, check the order state of the first order then either resubmit the second order or choose not to resubmit the second order depending on what behavior you want.

            http://www.ninjatrader.com/support/h...orhandling.htm

            http://www.ninjatrader.com/support/h...nt7/iorder.htm

            But if possible, I would submit OCO orders at the same time or not use OCO on them and use manual logic to manage the orders. (Detect the order has filled or is in the order state cancelled and then use logic to submit another order.)
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi,
              we can't submit OCO orders at the same time on CQG - that's why we have this problem in the first place.
              Your other option, to avoid any OCO and manually handle orders that require cancelling when their partners are filled, is basically "Local OCO" but handled by my code instead of the API. I don't see any advantage in that, only unnecessary coding work.
              As far as I can see that only leaves the one option; to handle all rejections. Is this correct? Is the only way to use live (not local) OCO with CQG is to turn off the auto-rejection handling?

              saltminer

              Comment


                #8
                Hello saltminer,

                Ah, the issue with compound leg orders.

                As is mentioned in the disclaimer for OCO with CQG / Continuum: "There will be an approximated 200ms delay between submission of strategy based stop and target orders".
                http://www.ninjatrader.com/Connectio...tion-Guide.php

                This actually means OCO orders and the delay is more like 250ms.

                You can choose to set the error handling to ignore rejects and resubmit.

                You can choose to add a 250ms delay by using a timer.
                (Let me know if you would like a working example of a timer)

                You can use Local OCO.

                These are basically the only options here I can think of.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Chelsea,
                  ok, but let me quote an earlier post that you can now address directly, since we've been around the mulberry bush a bit with this. Thanks.

                  I've coded such that the state of "Accepted" or "Working" must be received by the first leg of an OCO pair before the second leg is submitted.
                  However, this still causes problems.

                  An exit bracket has two orders, Ex0 and TS0.

                  The code correctly waited for order Ex0 on ZN 12-14 to reach the state of “Accepted”, and submitted its paired order TS0.
                  Problem was, while TS0 was on the road, Ex0 got filled. So by the time the OCO order got to the broker the original order had been filled, which meant that TS0 got rejected.

                  I don’t know how to get around this problem. Obviously at any stage an order can get filled; there is no “safe” time to submit a paired OCO order for one that is already working in the market. Waiting x milliseconds doesn’t solve anything, as you could wait x milliseconds, all clear, submit the order and still find that the first order of the pair gets filled while you’re doing it.
                  Regards,
                  saltminer

                  Comment


                    #10
                    Hi saltminer,

                    Are you saying you have added a timer to your code to wait 250ms before sending the next order, and this didn't work?

                    May I have an export of this script?

                    I ask because I was able to get this to work on my end.

                    To export your script do the following:
                    1. Click File -> Utilities -> Export NinjaScript
                    2. Enter a unique name for the file in the value for 'File name:'
                    3. Select the strategy from the objects list on the left -> click the right facing arrow ">" to add the strategy to the export
                    4. Click the 'Export' button -> click 'yes' to add any referenced indicators to the export -> click OK to clear the export location message


                    By default your exported file will be in the following location:
                    • (My) Documents/NinjaTrader 7/bin/Custom/ExportNinjaScript/<export_file_name.zip>


                    Below is a link to the help guide on Exporting NinjaScripts.
                    http://www.ninjatrader.com/support/h...nt7/export.htm
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Chelsea,
                      I wish you would read my posts properly. No, I didn't use a timer. I waited until in OnOrderUpdate() the first leg of the OCO reached "Accepted" or "Working". I then sent its OCO paired order. These are a typical stoploss and profit target pair.
                      Trouble is, while the second one was travelling along the internet to the broker, the first one got filled. The second order was (correctly) rejected.
                      This stuff is bound to happen if two OCO orders cannot be submitted together. A timer has no bearing on this issue.

                      I am asking for the recommend programming solution to this.It may be that custom rejection handling is the only solution, but that is my least favourite as it is fraught with its own hairy problems.

                      Thanks,
                      saltminer

                      Comment


                        #12
                        Hello saltminer,

                        I am saying the answer is to use a timer.

                        I have suggested you use a timer.

                        You are saying you have not used a timer.

                        There may not be a solution that will work for you if you do not want to follow these suggestions.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          sorry I have to ask very simple, in the wizard to create a single sign on bars with a length of 15 ticks for example, I set the aperture smaller than the closure offset 15 ticks, but the signal it creates on all bars

                          Comment


                            #14
                            sorry I have to ask very simple, in the wizard to create a single sign on bars with a length of 15 ticks for example, I set the aperture smaller than the closure offset 15 ticks, but the signal it creates on all bars

                            Comment


                              #15
                              Hi mylanel86,

                              I am not quite sure what you are trying to accomplish.

                              I do understand you have an object that is appearing on every bar and this is not the desired behavior.

                              May I see the code you are using?

                              When you mention aperture, can you clarify what you mean by this?
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by jclose, Today, 09:37 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post jclose
                              by jclose
                               
                              Started by WeyldFalcon, 08-07-2020, 06:13 AM
                              10 responses
                              1,414 views
                              0 likes
                              Last Post Traderontheroad  
                              Started by firefoxforum12, Today, 08:53 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post firefoxforum12  
                              Started by stafe, Today, 08:34 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post stafe
                              by stafe
                               
                              Started by sastrades, 01-31-2024, 10:19 PM
                              11 responses
                              169 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Working...
                              X