Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

oco doesn't work

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

    #16
    Hi,
    At 6:55:54, it was some tests without importance. At 10:58:29 it was the good behaviour, but the bad one was the one at 11:13:29. Indeed, the position at 10:58:29 buy 100 and sell 100. That's perfect. But, the reason I put this example here is to show that it works like OCO without any help of me (I do not cancel any order). That explain why I want target1 to be filled before submitting target2. If I submit target2 before target1 was filled it gonna be cancelled because of the oco between target1 and target2. That is not exactly oco but as I said before it is managed by NT(as specified again in this thread: http://ninjatrader.com/support/forum...?t=7624&page=2 : as specified by NinjaTrader_Ray: "There is internal OCO handling in place where if the stop is filled, it will cancel the target..." ).
    The problem is that, the target2 isn't cancelled as I want but changed. I never managed to change it. It makes no sense to me.

    I tried with different entry signal names, it is worse still it doesn't seems to accept that the entrysignal was an exitPosition, which is logic, but then which signal should I use.

    Thank you in advance,
    R.E.

    Comment


      #17
      Hi,
      My problem isn't resolved yet but I am experiencing reeal issues with NT. I can't reset the database and I think it is not about this but about serialization. I taked some screen shots to show the situation.

      Thank you in advance for helping me with the two issues,
      R.E.
      Attached Files

      Comment


        #18
        Hello R.E.,

        From the thread you linked in Ray's post #16.
        Right, OCO being blank is expected since the OCO is not an OCO order but part of internal strategy handling that cancels out orders.
        This is what I am talking about. Unless you are using SetStopLoss() and SetProfitTarget() in your managed strategy code OCO is not being used.

        However, by using signal names there is some internal logic that tries to cancel orders when their entry fills. This is not oco, however, in that when one of the attached orders is filled or cancelled the others are as well. This is strictly for attaching an exit order to an entry (ignoring any other orders that may also be attached to this entry, which will be trying cancel or fill on their own based on their signal name price etc).

        If you were using the unmanaged approach and using SubmitOrder() then you can absolutely use OCO all you would like.

        Likely, since your strategy is using logic that is attaching multiple orders to a single entry, I would suggest that you manually check for any orders that need to be cancelled and cancel them with CancelOrder(). Or I would suggest switching to the unmanaged approach where these rules aren't as confusing and the method is alot more straight forward as all logic will be managed by you.

        Regarding the issues you are having with deserialization, please send in an email to platformsupport [at] ninjatrader [dot] com with a link to this forum thread so that we can investigate this issue further without releasing any private information publicly.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #19
          Hi,

          Since I am new in NT, I prefer to avoid using the unmanaged approach before being sure of fully understanding the benefits of the managed approach.
          I am aware of the fact that it is not real OCO (since this field is blank in the log file), but I still thinking (I am maybe wrong), that I didn't get the internal logic that cancell orders attached to the same entry signal.
          The main question is why should this logic works at 10:58:29 (we buy and sell 100 contracts), and not at 11:13:29 (an order for 24 contracts still alive). Since "Print debugging", my logic and my code proove that I am not changing any order. Why my target2 isn't cancelled but changed?

          Thank you in advance,
          R.E.

          Comment


            #20
            Hello R.E.,

            I don't think that the code you have shared is the code you are running.

            In the code I am seeing that you are submitting the targets with 60 and 40 as the quantity. In the log the orders are taking 70 and 30.

            Further:
            Code:
            if(order!=null&& Porder==order && Porder.OrderState == OrderState.Filled)
            {
            ExitLongStop(0, true, 100, stop, order.Name+"stop", order.Name);
            ExitLongLimit(0, true, 60, target1, order.Name+"target1", order.Name);		
            }
            if(order!=null&& Porder==order && Porder.OrderState == OrderState.Filled&&order.Name.EndsWith("target1"))
            {
            ExitLongStop(0, true, 40, stop, order.Name+"stop", order.Name);
            ExitLongLimit(0, true, 40, target2, order.Name+"target2", order.Name);		
            }
            So when the entry order fills and the entry order name ends with "target1" then it will place the second exit long limit order.
            This is impossible. The entry order name will never end with "target1". This means you are not running this code and getting these results in the log.
            You have to be running different code.

            Where the second ExitLongLimit is being placed that is where the issue is. I can't see any way that the code you have provided is the actual code you are running. The logic in the log and the logic in the script do not agree.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #21
              Hi,
              You are perfectly right, it is not the same script: First time I attached this script I said that it is a script that try to create similar conditions than the real script (in my first message).
              You are also right when you say that there is bugs and errors. The thing is that I wanted to show the spirit of my code (and in fact created an other issue since it maked ninjatrader crash so I wasn't able to make sure the code works well), but you are right, it is impossible to see one day the second target activated (the solution is to delete the second condition..).
              Anyway, the other script is called ATS (as specified in the trace file) and is the one who created the trades I showed you. Since I am not the owner of the code I can't attach, and furthermore it is more than 1000 lines of code. But I can assert that I never make a change to the target2 order. Anyway the quantity 24 can't occurs since in my computations all the quantities are multiple to 10.

              Thank you for your help in advance,
              R.E.

              Comment


                #22
                Hi R.E.,

                I am not sure how to assist without knowing what the code is trying to do.

                I think that after the stop loss filled the Long2target2 was resubmitted and the issue is coming from that code right there.

                Its hard to say because the code you submitted won't actually trigger because of the logic in it.

                I think you should probably talk with a consultant and have them correct the logic of your script. Or go to the original author of the script and let them know the issue and about when the issue is presenting itself.

                Do you want a link to the NinjaScript consultants list?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #23
                  Thank you for all your help,

                  I know how hard it is to debug without seeing the code. To make it easier, I have now a code working and reproducing the bug. Furthermore I have the log file and screenshots that's shows the problem.

                  The problem comes from the 24 contracts of the target2. The interesting part in the log file begins at 17:55:22.
                  To reproduce the issue, it is simple: You can use my script and change the width of the line ploted at y=1 (I did this because NT opens positions with historical data when I run the strategy and block the strategy). Then make the price go down for 1 tick (the use of simulated connexion is mandatory). After, let the price crosses the target1, and then go down to the stopLoss. Then, make the price rise up towards the second target which will be activated and it isn't what we are expecting.

                  Thank you,
                  R.E.
                  Attached Files

                  Comment


                    #24
                    Hi R.E.,

                    The issue is there where the second target is being placed as I expected.

                    You are attempting to change the quantity for the stop even though NinjaTrader's handling is already doing this. By trying to change the quantity for the stop you are throwing off NinjaTrader's ability to change the quantity of the stop. This means the association is thrown off and the remaining quantity internally to the entry signal name is incorrect.

                    In other words, if you are going to use the managed approach then let NinjaTrader manage those orders and don't try and manage them yourself.

                    Or switch to the unmanaged approach.

                    Attached is the script with the line of code causing the issue removed.


                    Also, just a small tip, having an importable file will ensure that all depencies are met when exporting and can ensure that your file does not have any programming errors.
                    There's nothing wrong with sharing a .cs file, but having an export is sometimes helpful.

                    Follow these steps to import the NinjaScript:
                    1. Download the script to your desktop, keep it in the compressed .zip file.
                    2. From the Control Center window select the menu File > Utilities > Import NinjaScript
                    3. Select the downloaded .zip file
                    4. NinjaTrader will then confirm if the import has been successful.

                    Critical *Note that on any files that say "File already exists on your PC" that start with an "@" symbol are the ones that came preloaded inside of NinjaTrader so you would say "No" so that you do not override those files.

                    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
                    Attached Files
                    Last edited by NinjaTrader_ChelseaB; 08-24-2015, 03:46 PM.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #25
                      Hi,
                      If I use your strategy, it makes it impossible for my position to be flat at the end of the trade. A simple solution is to use two different names for my stopLoss: when the first one is cancelled, I submit the second one. So, let's admit this solution works, I think it will. Now, I am asking for safe implementation if possible: Thanks to you, I know it is a bad practice to change the quantity of orders. Now what I am asking for if it is a bad practice to change the limit price with an exitlonglimit method (and also with a stopLoss) and if not, I will have a last questions for you please:

                      How is the best way to create a trailStopLoss (then without SetStoploss() ) and multiple profit target, using the managed approach?

                      Thank you in advance,
                      R.E.

                      Comment


                        #26
                        Hello R.E.,

                        In my testing I thought I had resolved that but I am seeing that is not the case.

                        In this case, the original stop needs to be cancelled and re-submitted. (or the original stop cancelled and a different stop submitted.)

                        Attached is the same strategy modified again to show this change. (I've made sure that this works.)

                        (edit)
                        Also, attached is an example of a trailing stop that doesn't use set stop loss.
                        Attached Files
                        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