Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Issue with entryOrder resetting to null in OnOrderUpdate

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

    Issue with entryOrder resetting to null in OnOrderUpdate

    I am running into problems again with my entryOrder disappearing. It doesn't do it all the time, which is weird. But I've noticed that when it does, it's looping through OnOrderUpdate. So how does OnOrderUpdate work? I have two entryOrders both with their own signals and the get assigned within OnOrderUpdate. I have Prints everywhere, so it is not going the OnExecutionUpdate at this point. What I have noticed is, it's trying to do both orders at the same time...and at the end of OnOrderUpdate my first entryOrder is there, but when it loops again with the Accepted Status, entryOrder is now null. The only time I have code to set it to null is when MarketPosition becomes flat, or after OnExecutionUpdate gets filled, but as I mentioned before, it doesn't seem to be entering OnExecutionUpdate yet. I have got it to provide this error again and this is the Output. In this case, my second entryOrder is being assigned to entryOrder2, at which point you can see that the previous order, entryOrder was assigned. It goes back to the first order, and entryOrder has disappeared. Is there something within OnOrderUpdate that I'm missing?

    entryOrder: orderId='5e3f9639abcf4edb90f29cb64d8371a2' account='Sim101' name='ShortPullback 1' orderState=Submitted instrument='MYM 03-25' orderAction=SellShort orderType='Market' limitPrice=0 stopPrice=0 quantity=4 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=27648 time='2025-03-03 13:28:09' gtd='2099-12-01' statementDate='2025-03-03'
    entryOrder2: orderId='4468b8630ed8458cbcb069b265233e22' account='Sim101' name='ShortPullback 2' orderState=Submitted instrument='MYM 03-25' orderAction=SellShort orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=27649 time='2025-03-03 13:28:09' gtd='2099-12-01' statementDate='2025-03-03'
    Removing ShortPullback 2 from entryAssignments
    entryOrder: orderId='5e3f9639abcf4edb90f29cb64d8371a2' account='Sim101' name='ShortPullback 1' orderState=Submitted instrument='MYM 03-25' orderAction=SellShort orderType='Market' limitPrice=0 stopPrice=0 quantity=4 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=27648 time='2025-03-03 13:28:09' gtd='2099-12-01' statementDate='2025-03-03'
    entryOrder2: orderId='4468b8630ed8458cbcb069b265233e22' account='Sim101' name='ShortPullback 2' orderState=Submitted instrument='MYM 03-25' orderAction=SellShort orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=27649 time='2025-03-03 13:28:09' gtd='2099-12-01' statementDate='2025-03-03'
    Ending OnOrderUpdate
    entryOrder: orderId='5e3f9639abcf4edb90f29cb64d8371a2' account='Sim101' name='ShortPullback 1' orderState=Submitted instrument='MYM 03-25' orderAction=SellShort orderType='Market' limitPrice=0 stopPrice=0 quantity=4 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=27648 time='2025-03-03 13:28:09' gtd='2099-12-01' statementDate='2025-03-03'
    entryOrder2: orderId='4468b8630ed8458cbcb069b265233e22' account='Sim101' name='ShortPullback 2' orderState=Submitted instrument='MYM 03-25' orderAction=SellShort orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=27649 time='2025-03-03 13:28:09' gtd='2099-12-01' statementDate='2025-03-03'
    stopOrder:
    stopOrder2:
    targetOrder:
    targetOrder2:

    Entering OnOrderUpdate
    order.Name ShortPullback 1
    order.OrderState: Accepted
    entryOrder:
    entryOrder2: orderId='4468b8630ed8458cbcb069b265233e22' account='Sim101' name='ShortPullback 2' orderState=Submitted instrument='MYM 03-25' orderAction=SellShort orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=27649 time='2025-03-03 13:28:09' gtd='2099-12-01' statementDate='2025-03-03'
    stopOrder:
    stopOrder2:
    targetOrder:
    targetOrder2:
    entryAssignments.Count: 0
    OrderState == Accepted
    entryOrder:
    entryOrder2: orderId='4468b8630ed8458cbcb069b265233e22' account='Sim101' name='ShortPullback 2' orderState=Submitted instrument='MYM 03-25' orderAction=SellShort orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=27649 time='2025-03-03 13:28:09' gtd='2099-12-01' statementDate='2025-03-03'
    stopOrder:
    stopOrder2:
    targetOrder:
    targetOrder2:
    Ending OnOrderUpdate​

    #2
    Hello rockmanx00,

    OnOrderUpdate is called for each order event. You need to use conditions in that override to check for order names and status if you are assigning or resetting variables there. If you have two entry orders you should have two separate blocks of code in OnOrderUpdate with 2 separate entry order variables being assigned and cleared when needed.

    Comment


      #3
      I do have that, they are assigned separately and each entryOrder (entryOrder and entryOrder2) are nulled if OrderState.Cancelled in OnOrderUpdate, or within OnExecutionUpdate. I have Prints there too, so it doesn't look like it's getting that far. It seems to be going from the assignment of entryOrder2, going back to entryOrder but that original entryOrder is gone for some reason. And this doesn't always happen.

      Here's another example. In all cases of this not working, it's going from OnOrderUpdate working on the second order, then to a different instance of OnOrderUpdate but on the first order. Is there something in between OnOrderUpdates that I'm missing that I can add Prints to? At this point, all I know is it disappears, and I can't add anymore Prints to figure out how to prevent this from happening. Again, it doesn't happen all the time. I have had cases where it still does that same order of working on the second order, then jumping back to the first but entryOrder is still there.

      Entering OnOrderUpdate
      order.Name LongMarket 2
      order.OrderState: Working​
      Ending OnOrderUpdate
      entryOrder: orderId='ee6c64cc5bb5495b84f5063deab513b4'
      entryOrder2: orderId='df046b3bcd484ac38aca0a486724a916'
      stopOrder:
      stopOrder2:
      targetOrder:
      targetOrder2:

      Entering OnOrderUpdate
      order.Name LongMarket 1
      order.OrderState: Filled
      entryOrder:
      entryOrder2: orderId='df046b3bcd484ac38aca0a486724a916'
      Last edited by rockmanx00; 03-03-2025, 01:53 PM.

      Comment


        #4
        Hello rockmanx00,

        The events in OnOrderUpdate are as status changes happen so there is not a specific order. Do you have two separate blocks of code that can run independently to assign variables based on the incoming order status? You should see one event for one entry and then a separate event for the other entry.

        Comment


          #5
          I am currently using a dictionary entryAssignments that saves the Signal Name and the Tag to differentiate whether I want to assign the order to entryOrder or entryOrder2. That dictionary entry is added before I enter long or short, and is removed in OnOrderUpdate as soon as it detects the signal name and assigns the order accordingly. I'm mainly using OnOrderUpdate to do the assignments of the entryOrder and everything else is done in OnExecutionUpdate. Does that answer your question?

          Comment


            #6
            Hello rockmanx00,

            It sounds like your dictionary is not working right. You would need to add items to the dictionary when OnOrderUpdate is called except for specifically filled events, at that time you could remove them. I would suggest to simplify the code to just use variables unit you have it working exactly right, at that point you could implement more complex collections like a dictionary.

            Comment


              #7
              It seems like the dictionary is working fine though? At the end of OnOrderUpdate you can clearly see both entryOrder and entryOrder2 assigned properly. But when it goes back to work on the first order, entryOrder is just gone for some reason. The dictionary is only there for assigning entryOrder vs entryOrder2. The issue is with entryOrder disappearing and the dictionary doesn't have anything to do with that after entryOrder or entryOrder2 is assigned. I'll try a few things and see. This is really stumping me though,

              Comment


                #8
                Hello rockmanx00,

                If your logic is not working as expected then its likely not working right.

                I would suggest looking at the OnOrderUpdate sample which shows how to assign variables and null them when finished. https://developer.ninjatrader.com/do.../onorderupdate

                The only other reason to null the order would be if it was fully filled in OnExecutionUpdate.

                Comment


                  #9
                  Yeah, the only places I have it nulled is if the OrderState in OnOrderUpdate is Cancelled, or in OnExecutionUpdate which it is not even getting to that point when I'm getting these errors. I will take a look at your sample and see if I can't get it figured out. Thank you very much.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NullPointStrategies, Today, 05:17 AM
                  0 responses
                  44 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  124 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  65 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