Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

oco doesn't work

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

    oco doesn't work

    Hi,
    I got a problem with a strategy. I use exitLongLimit/stop and enterLongLimit. It seems to work fine in the beginning but while I used a lot of exits it seems that the oco doesn't work. My logic is very simple, I simulate a trail stop using exitlongstop a lot of times, and I simulate a double target thanks to the quantity of my orders.
    The scenario that makes me crazy is the following one:
    I buy 100 contracts of some currency
    I place an exit limit for 60 contracts and an exit stop for 100 contracts.
    We reach our target so I place an exit limit for 40 contracts and an exit stop for 40 contracts.
    We can reach a level that makes me activate the trail stop ( an other call to exitstop with the good quantity)
    Then we assume the prices went down and then I activate the exit stop. The result is that the target 2 still alive and the quantity change to 24.
    The log/ Trace files don't show something weird. It is like I did it is impossible from the moment that I modify the target 2 only and only if when the target1 is crossed. I can't understand the problem and I am trying to reproduce it but I got issues with this, I doesn't know why the order update refuse to work. I attached my try which doesn't work.

    Thank you in advance,
    R.E.
    Attached Files

    #2
    Hello snoppss,

    Are you trying to re-use OCO ids after they've been used on an order that has filled or been cancelled?

    With some brokers, if an order is filled or cancelled using an OCO ID, all orders from that point forward using that OCO ID will be ignored.

    This means that it is very important that once you've placed a pair of orders with OCO, that a new unique OCO that has never been used before is used for the new set of orders.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi,
      thank you for your answer,
      I use no broker since I use the simulated connection to run the tests.
      I don't use the oco id because it is not oco sent to broker but simulated by ninjatrader.
      In the trace file the field oco is empty. I don't really know if I use OCO ids, do you think I should modify the name of the stop loss when I change it when I cross the target1. Or should change the signal entry when the first oco is executed? In this case what entry signal gonna match?

      Thank you in advance,
      R.E.

      Comment


        #4
        Hello R.E.,

        I was basically responding to the following:
        I use exitLongLimit/stop and enterLongLimit. It seems to work fine in the beginning but while I used a lot of exits it seems that the oco doesn't work
        I was hearing that this was the issue that you are having, and this possibly is causing orders to not be submitted.

        Looking at the code in the file you attached, this is using the managed approach and is not able to use OCO for your ExitLong order types.

        If you are not using OCO with your orders, what is the issue that you are having?
        (Please try and let me know the direct issue without describing a scenario)

        I am not seeing any trailing logic in the script. If the position is flat then a few variables are reset. If an order called Porder fills then a couple of exit orders are placed.
        Are you asking questions about the script that you have attached to your post? Was this accidently the wrong script attached?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          The real script have more than 1000 lines then I tought it is not relevent to attach it: I tried to do an other script to summarize the issue. But the ssecond script doens't work and I don't see why. I change some stuffs in the if statement because it was false but it is not better.
          Anyway the real problem is that the exitlonglimit and exitlongstop are oco simulated like they said it here : http://ninjatrader.com/support/forum...?t=7624&page=2. it's the second answer.
          So it should work for me, and indeed if I defined exitlimit and exitstop for an order, the oco works perfectly. The problem occurs when I use the first oco and use a second one: When an exitlimit or loss is crossed the first time it work but if I define a second time exit orders it go crazy.

          Thank you in advance,
          R.E.

          Comment


            #6
            Hello R.E.,

            You cannot use OCO with ExitLongLimit or ExitLongStop.

            Maybe this is the issue you are having?

            If you want to use OCO you need to switch to the unmanaged approach.

            I still don't understand what the issue is. Did an order fill at an unexpected price? Did an order fail to be submitted? Did an order that was submitted fail to fill? Are orders appearing that you are not expecting?

            What is the issue?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              The thing is with ExitLongLimit or ExitLongStop I have the oco. It is simulated and computed by NT but not sent to the broker: I am sure of that because I saw it in the log file: an execution of the stop causes the cancellation of the target.
              The problem is that I have two targets and when the stop is crossed ( after the first target was crossed, and then the oco applied once), the second target change by itself and doesn't be cancelled. It is what I explain in more detail in the first scenario (first post).

              Thank you in advance,
              R.E.

              Comment


                #8
                Hello R.E.,

                I am still not understanding the issue.

                OCO cannot be used with ExitLongLimit or ExitLongStop.

                Have you coded into your script manual logic that calls CancelOrder() on an IOrder?

                Is this manually coded logic not working correctly?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  I coded nothing to manage oco orders, from the moment exitlonglimit and exitlongstop are managing oco if there are associated to the same entry signal. Now I have two issues, and here is my log files to show you exactly my problems.
                  First of all, here is an example of oco with exitlonglimit/stop: at 10:58:20 we initiate a long position we associate to it a stop and a first target then the stop is crossed and the target is cancelled without any use of cancel method from me( there is no occurence of cancel in my code for targets or stops: and as you can see my conventions make it easy to be sure to know what type of order we are cancelling, so as expected the oco work very well).
                  Now here is an example of something that doesn't work: at 11:13:29 we go long we crossed the first target the stop is changing (that's nice because we want the trail stop) but when the stop is crossed you can see that the second target is doing a weird change that I can't explain what is happenig at 11:19:57 (That's my issue, still I never modify the second target) .
                  Anyway I was creating a little script to show you my issue but NT refuse to work and to activate any strategy, you can see the messages I got at the end of the log file ( eg: 19:30:18, 19:34:40...) I resetted the database but still not working.

                  Thank you in advance,
                  R.E.
                  Attached Files

                  Comment


                    #10
                    Hello snoppss,

                    Thank you for your response.

                    I see the order properly adjusts which would be indicated by the PendingChange. What behavior is unexpected for you? What behavior are you expecting? Please provide detailed on this.

                    To resolve the errors and the strategies not starting you would need to reset the database. This can be performed by going to Tools > Options > Data > Reset Database.

                    Comment


                      #11
                      Hi,
                      I am expecting that the target2 be cancelled by the oco like at 10:58:20, the change isn't created by my strategy. There is no explanation I can give to the value 24!!

                      The reset of the DB doesn't fix the problem, I also get this now: Failed to execute DB job 'StrategyUpdateJob'... it is about sereialisation. I am connected with the simulator and here is the script which caused this for the first time.

                      Thank you in advance,
                      R.E.
                      Attached Files

                      Comment


                        #12
                        Hello snoppss,

                        Thank you for your response.

                        You can rename your database by following the steps below.
                        • Shutdown NinjaTrader and Go to the Start Menu
                        • Select My Documents--> NinjaTrader 7--> DB--> NinjaTrader.SDF.
                        • Right click on NinjaTrader.SDF and select "Rename." *Name it "OLDNinjaTrader.SDF."
                        • Then restart the software and NinjaTrader will create a fresh database file to use
                        • Unfortunately the following items stored in the old database will be lost - ATM Strategy templates, Session templates, Instrument Lists / Custom Instruments, historical trade execution data, saved Strategy Analyzer backtest results

                        To prevent running into situations where you can potentially lose important data, we advise to run regular backups via our inbuild backup feature in NinjaTrader.

                        Comment


                          #13
                          Hi,
                          Thank you for your answer, but for my first problem I didn't found a solution yet. I mean, if I have a signal entry and then I applied the oco once can I use the same entry signal and expect from it to work for a second oco?.
                          I mean, if I have 100 contracts and then my exits closes 50 contracts if I use exit again to close the 50 that remains, will it also be oco ??

                          Thank you in advance,
                          R.E.

                          Comment


                            #14
                            Hello snoppss,

                            Thank you for your response.

                            Yes, the second set of exits would still be valid. Have you tried giving them each different SignalNames?

                            Comment


                              #15
                              Hello R.E.,

                              I want to re-iterate that I am not seeing that OCO is being used in this script whatsoever.

                              Using signal names is not the same thing as OCO. Are you considering using signal names as the same thing as using an OCO Id?


                              Taking a look at the orders at 10:58 I am seeing the following:

                              Your position starts at 70 from the previous orders.

                              20/08/2015 07:35:25|1|64|Instrument='$EURUSD' Account='Sim101' Avg price=1,0906 Quantity=70 Market position=Long Operation=Insert Currency=Unknown

                              Long0 fills with a quantity of 100:
                              20/08/2015 10:58:29|1|32|Order='40ba7df99602412a83e578ebcb82b 76c/Sim101' Name='Long0' New state=Filled Instrument='$EURUSD' Action=Buy Limit price=1,0507 Stop price=0 Quantity=100 Type=Limit Filled=100 Fill price=1,0507 Error=NoError Native error=''

                              This brings the position to 170
                              20/08/2015 10:58:29|1|64|Instrument='$EURUSD' Account='Sim101' Avg price=1,06712941176471 Quantity=170 Market position=Long Operation=Update Currency=Unknown

                              Long0stop and Long0target1 are submitted:
                              20/08/2015 10:58:29|1|32|Order='f03673081dd449558ca3b460cda24 03f/Sim101' Name='Long0stop' New state=PendingSubmit Instrument='$EURUSD' Action=Sell Limit price=0 Stop price=1,0479 Quantity=100 Type=Stop Filled=0 Fill price=0 Error=NoError Native error=''
                              20/08/2015 10:58:29|1|32|Order='9ac8926caea045c997578e132e0ab ae4/Sim101' Name='Long0target1' New state=PendingSubmit Instrument='$EURUSD' Action=Sell Limit price=1,053 Stop price=0 Quantity=30 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''

                              But there is no Long0target2 order that is submitted at this time.

                              Long0stop then fills:
                              20/08/2015 10:59:45|1|32|Order='f03673081dd449558ca3b460cda24 03f/Sim101' Name='Long0stop' New state=Filled Instrument='$EURUSD' Action=Sell Limit price=0 Stop price=1,0479 Quantity=100 Type=Stop Filled=100 Fill price=1,048 Error=NoError Native error=''

                              And Long0target1 is cancelled:
                              20/08/2015 10:59:46|1|32|Order='9ac8926caea045c997578e132e0ab ae4/Sim101' Name='Long0target1' New state=Cancelled Instrument='$EURUSD' Action=Sell Limit price=1,053 Stop price=0 Quantity=30 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''


                              The trade is exited correctly and the position is back to where it started at 70.
                              20/08/2015 10:59:45|1|64|Instrument='$EURUSD' Account='Sim101' Avg price=1,06712941176471 Quantity=70 Market position=Long Operation=Update Currency=Unknown

                              There is no Long0target2 that is submitted at this time.


                              I am still uncertain of the issue you are experiencing. For the trade that happened at 10:58 this entered and exited without issue.


                              As I mentioned, you are not using OCO. There is no OCO in your strategy.

                              I am seeing that your logic can cause the position to not go back to flat.
                              For instance at 6:55:54:

                              An order is sent to enter a position called Long0:
                              20/08/2015 06:55:54|1|32|Order='b0d73ec5109f406c8c7319fbc522c 84f/Sim101' Name='Long0' New state=Filled Instrument='$EURUSD' Action=Buy Limit price=1,1174 Stop price=0 Quantity=100 Type=Limit Filled=100 Fill price=1,1174 Error=NoError Native error=''

                              This brings the position to long 100:
                              20/08/2015 06:55:54|1|64|Instrument='$EURUSD' Account='Sim101' Avg price=1,1174 Quantity=100 Market position=Long Operation=Insert Currency=Unknown

                              A order is then placed called Long0stop for 100 and a second order called Long0target1 is submitted for 30.
                              20/08/2015 06:55:54|1|32|Order='343deb72f48344b6bcacbc65019fe cf9/Sim101' Name='Long0stop' New state=PendingSubmit Instrument='$EURUSD' Action=Sell Limit price=0 Stop price=1,1141 Quantity=100 Type=Stop Filled=0 Fill price=0 Error=NoError Native error=''
                              20/08/2015 06:55:54|1|32|Order='ee983dffff594558a2d13e8141c49 474/Sim101' Name='Long0target1' New state=PendingSubmit Instrument='$EURUSD' Action=Sell Limit price=1,1201 Stop price=0 Quantity=30 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''

                              Then you wait until Long0target1 is filled before you submit Long0target2.
                              20/08/2015 06:57:06|1|32|Order='ee983dffff594558a2d13e8141c49 474/Sim101' Name='Long0target1' New state=Filled Instrument='$EURUSD' Action=Sell Limit price=1,1201 Stop price=0 Quantity=30 Type=Limit Filled=30 Fill price=1,1202 Error=NoError Native error=''

                              This brings the position to Long 70.
                              20/08/2015 06:57:06|1|64|Instrument='$EURUSD' Account='Sim101' Avg price=1,1174 Quantity=70 Market position=Long Operation=Update Currency=Unknown

                              After the Long0target1 fills, then Long0target2 is submitted (why are you waiting for the first target to fill before placing the second target?):
                              20/08/2015 06:57:06|1|32|Order='a14dfe6fa0db4dd3874fa122e542d fa7/Sim101' Name='Long0target2' New state=PendingSubmit Instrument='$EURUSD' Action=Sell Limit price=1,1241 Stop price=0 Quantity=70 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''

                              Then about 10 minutes later both the Long0stop and Long0target2 are both cancelled.
                              20/08/2015 07:07:32|1|32|Order='a14dfe6fa0db4dd3874fa122e542d fa7/Sim101' Name='Long0target2' New state=Cancelled Instrument='$EURUSD' Action=Sell Limit price=1,1241 Stop price=0 Quantity=70 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
                              20/08/2015 07:07:33|1|32|Order='343deb72f48344b6bcacbc65019fe cf9/Sim101' Name='Long0stop' New state=Cancelled Instrument='$EURUSD' Action=Sell Limit price=0 Stop price=1,1141 Quantity=70 Type=Stop Filled=0 Fill price=0 Error=NoError Native error=''

                              This leaves the position unprotected at Long 70.


                              I do not see that the trade at 10:58 has experienced any issue.
                              Can you clarify what the unexpected behavior was, and what the expected behavior is?
                              Last edited by NinjaTrader_ChelseaB; 08-20-2015, 02:43 PM.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

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