Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnExecutionUpdate not submitting OCO orders

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

    OnExecutionUpdate not submitting OCO orders

    Hello, after about 6 months of working on my strategy, I'm happy to say I'm in the home stretch. The only issue remaining (for now, at least) is that my exit orders are not OCO. I'm managing orders based on the OnOrderUpdate example used in the guide. And for your reference, here are the lines of code in that example that create the exit orders:

    Code:
    [B]// Submit exit orders for partial fills[/B]
    
    if (execution.Order.OrderState == OrderState.PartFilled)
    
    {
    
    stopOrder = ExitLongStopMarket(0, true, execution.Order.Filled, execution.Order.AverageFillPrice - 4 * TickSize, "MyStop", "MyEntry");
    
    targetOrder = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AverageFillPrice + 8 * TickSize, "MyTarget", "MyEntry");
    
    }
    I know this particular code refers to partial fills, but rather that include the complete code, I just wanted to use this as an example. Should this code create an OCO order? If so, what about how these orders are written tells NT to do so?

    Mark

    #2
    Hello maltin,

    The managed approach uses signal names to link targets to a position/entry. You don't need to worry about OCO in the managed approach. If you were using the unmanaged approach you would need to specify an OCO.

    Comment


      #3
      Thanks Jesse! The issue I came across was that I entered a trade using a strategy I build. Both the take profit and stop loss were "working" on the server. Before either was hit, I had to shut down the computer the strategy was running on and monitor the trade from my phone. When my target was hit, I noticed the stop order wasn't canceled. Not a huge deal because I canceled it from my phone.

      Usually, strategy will cancel the other order. I have lines in my code to do this. If there was a way to link the orders on the server as OCO so I wouldn't have to worry on days where my computer is directly managing the trade.

      Comment


        #4
        Hello maltin,

        This would be due to having the platform closed, the platform needs to know if the associated position is closed to cancel the opposite target when using signal names. If the platform was opened it would have worked as you were expecting. To have server side OCO orders you would need to use the Set methods or the unmanaged approach instead of submitting individual orders like you had shown in your first post. The Set method orders are submitted with OCO and in unmanaged you can specify an OCO.

        Comment


          #5
          Thank you again. Jesse, this is valuable insight. I started with the set methods. At this point, I'm not sure why I gave up them. Since then, my code has tightened up a bit. I'll give them another try. Especially, since I'm having a separate issue with order execution and partial fills. As seen here: https://forum.ninjatrader.com/forum/...er-and-servcer

          Comment


            #6
            Hello maltin,

            If you switch to using the set methods you can remove the OnExecutionUpdate logic because the set methods are submitted based on the entry filling similar to what you are doing now.

            The set methods are also based on the entries average fill price so you should be able to use the offsets with ticks to do the same type of orders. The only thing to make sure of would be that if you submit the set methods from OnBarUpdate make sure to call the set methods before the entry

            SetStopLoss()
            EnterLong()

            Looking at your other post it would be hard to say what may be happening without running it and printing out the events. We do have a sample that has basic support for part filled orders, you can see that here: https://ninjatrader.com/support/help...and_onexec.htm

            Comment


              #7
              Hey Jesse, Removing the OnExecutionUpdate logic and getting server side OCO make compelling reasons to work in the Set methods. My TP and SL prices are calculated based on the ES price at the NYSE market open (9:30 ET). Once the price levels are calculated, they won't change for the duration of the trade. So, I do think I need them in the OnBarUpdate section.

              If I'm determining your example, when you say before, it only has to be one line before. Does it matter which order you set the TP and SL or no as long as they are both before the entry?

              Comment


                #8
                Hello maltin,

                The set methods can go anywhere in OnBarUpdate so long as that is called before the entry is submitted. It can be one line before or at the top of OnBarUpdate wherever works with your existing logic. It does not matter which order you call the targets, that just gets them ready so that when the entry fills they use correct prices for that specific entry.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Today, 05:17 AM
                0 responses
                50 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                127 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                69 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                42 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                46 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X