Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unexpected OCO Behavior

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

    #16
    I was able to see this working the way you describe and working the way you would like.

    The difference relates to whether NinjaTrader can pick up the exact same position information on the strategy restart.

    If there's any difference in price, date / time then there is not an actual account execution that the orders can be associated with, and you will see the same OCO id for all targets and stop losses.
    Ryan M.NinjaTrader Customer Service

    Comment


      #17
      Interesting, there is a lot going on behind the scenes. I have been amazed at times when NT has been able to automatically recover from a problem.

      I wonder if it would better to not tie all the orders together with OCO?

      BTW... The support team with NinjaTrader is fantastic. Great responses and response times.
      The Trading Mantis
      NinjaTrader Ecosystem Vendor - The Trading Mantis

      Comment


        #18
        OnExecution Method in Strategy not called

        I am having the same issue again that I outlined below.

        When I have a position in a strategy and a Target is filled, OnExecution is not called. It is called when I get an initial entry fill and any subsequent entry fills. The targets are limit orders.

        The first statement in the OnExecution method is:

        PHP Code:
        protected override void OnExecution(IExecution execution)
        {
        Print(Time[0]+" In OnExecution"); 
        
        This statement does not show up in the Output window after a target is filled.

        The Position tab in Control Center correctly reports the position size after any target fills. The log also shows the fills.

        I've attached the trace and log files.

        I did not have this problem earlier today. Later in the day, after the Strategy was running for awhile, I noticed my stops were not being adjusted. This is done in OnExecution after each target is filled.
        Attached Files
        The Trading Mantis
        NinjaTrader Ecosystem Vendor - The Trading Mantis

        Comment


          #19
          One other observation... The entry fills, but not the target fills, show up on the chart that I am running the strategy on.
          The Trading Mantis
          NinjaTrader Ecosystem Vendor - The Trading Mantis

          Comment


            #20
            I've done some more testing. Everything works fine when I run it from the Strategy Tab using the Market Replay Connection. When I run the strategy from a Chart using Market Replay, I get the same problem as outline below... OnExecution is not being called after Target fills .
            The Trading Mantis
            NinjaTrader Ecosystem Vendor - The Trading Mantis

            Comment


              #21
              Greg, could you please share the sample strategy you used for testing, so we can attempt to reproduce this issue here on B20? If you don't want to post it, please send it directly to support at ninjatrader dot com to my Attn.

              Thanks in advance.

              Comment


                #22
                Attached is the strategy. Keep in mind this was working fine (i.e. calling OnExecution as expected). After running it for awhile where I was repeatedly starting and stopping the strategy, closing the position on IB, modifying parameters, ect., it stopped calling OnExecution for the limit order fills.

                When I had this problem previously, renaming the strategy seemed to solve the problem. I tried renaming this time and it did not help.

                Thanks
                Attached Files
                The Trading Mantis
                NinjaTrader Ecosystem Vendor - The Trading Mantis

                Comment


                  #23
                  Hi Greg, we could unfortunately not reproduce here for now - the OnExecution() was called on B20 as expected for entries, stop and target fills. Could it be your strategy just was disabled and hence OnExecution() not called as you manually cancelled / working orders outside of the strategy?

                  Comment


                    #24
                    Hi Bertrand, I am also using B20. Strategy was/is definitely running.

                    Attached is a screen shot of the Output window from the strategy. You can see where the quantity changed at 8:31 indicating a Target was filled., but the Print statement Print(Time[0]+"In OnExecution"); was never executed. This was the only strategy running at the time and I was not making any manual entries or cancellations.

                    I almost think there is something stored in a configuration file or cache file somewhere that is causing this. Short of a complete uninstall/reinstall, are there cached files I can delete to see if that resolves the problem?

                    I had this problem last week with a prior version of this this strategy. The problem went away but I am not sure exactly what I did, except renaming the file.

                    Any other suggestions or ideas would be appreciated.

                    Thanks
                    Attached Files
                    The Trading Mantis
                    NinjaTrader Ecosystem Vendor - The Trading Mantis

                    Comment


                      #25
                      I found what was causing the behavior below (On Execution not called for Limit Order Target fills).

                      I did a complete uninstall of NT7 including deleting the NinjaTrader 7 directory in documents. I rebooted than reinstalled NT7. I copied over the strategy that was causing problems and ran it. The same problem still occurred, so I assumed it had to be something in the strategy.

                      After sequentially removing sections of the code, I found the following statement in the Initialize method was causing the behavior:

                      ExcludeTradeHistoryInBacktest = true;

                      I was able to confim this is the problem by uncommenting the line and running the strategy and then commenting the line and running the strategy repeatedly. The problem is reproducible. Not sure why you are not seeing it on your end.

                      Hope this helps.
                      The Trading Mantis
                      NinjaTrader Ecosystem Vendor - The Trading Mantis

                      Comment


                        #26
                        Thanks for pointing this out Greg - I'll play with this propery in my code and recheck shortly.

                        Comment


                          #27
                          I could finally reproduce and have fwd the issue to our dev team to check into - thanks for reporting.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          569 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          330 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
                          548 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          548 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X