Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error: "a historical order that has transitioned to a live order"

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

    Error: "a historical order that has transitioned to a live order"

    Before going into the issue, let me explain the "context":

    I did an old algorithm, that uses "unmanaged approach" from NT7 and never had any issues regarding orders, live or simulated. After transitioning to NT8 and rewriting it accordingly, I decided to do some tests, first under simulation, which has been running for several days and all seems right. Every day, I start the algo at 6:00pm, so all data is real-time until 5:00pm next day. Today, the first weird issue: the Algorithm submitted an order at 08:02 am, but this remained unfilled cause the market moved. The order kept working and finally at 08:40 am, the order finally got filled, but after that, the I get the weird message

    "2023-11-17 08:40:45:346|0|4|Strategy 'XXXYYY' has been disabled because it attempted to modify a historical order that has transitioned to a live order. Please see the help guide for more information on transitioning order references from historical to live.

    So, since it makes no sense cause all data has been real-time and not historical, I can't understand. So I pulled out the LOG and TRACE info regarding this issue, so you can take a quick look right away:

    LOG
    2023-11-17 08:02:47:331|1|32|Order='da15fe4022194b19b6bfc03dc d6c453e/Sim101' Name='SET LONG' New state='Submitted' Instrument='MES DEC23' Action='Buy' Limit price=4534 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    2023-11-17 08:02:47:473|1|32|Order='da15fe4022194b19b6bfc03dc d6c453e/Sim101' Name='SET LONG' New state='Accepted' Instrument='MES DEC23' Action='Buy' Limit price=4534 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    2023-11-17 08:02:47:475|1|32|Order='da15fe4022194b19b6bfc03dc d6c453e/Sim101' Name='SET LONG' New state='Working' Instrument='MES DEC23' Action='Buy' Limit price=4534 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    2023-11-17 08:40:45:268|1|32|Order='da15fe4022194b19b6bfc03dc d6c453e/Sim101' Name='SET LONG' New state='Filled' Instrument='MES DEC23' Action='Buy' Limit price=4534 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='' Filled=1 Fill price=4534 Error='No error' Native error=''
    2023-11-17 08:40:45:276|1|8|Execution='5d9c1e11b22c43f1b1645a f4e1a3fecb' Instrument='MES DEC23' Account='Sim101' Exchange=Default Price=4534 Quantity=1 Market position=Long Operation=Operation_Add Order='da15fe4022194b19b6bfc03dcd6c453e' Time='11/17/2023 8:40 AM'
    2023-11-17 08:40:45:343|1|64|Instrument='MES DEC23' Account='Sim101' Average price=4534 Quantity=1 Market position=Long Operation=Operation_Add
    2023-11-17 08:40:45:346|0|4|Strategy 'RCS/311242239' has been disabled because it attempted to modify a historical order that has transitioned to a live order. Please see the help guide for more information on transitioning order references from historical to live.

    TRACE
    2023-11-17 08:02:47:149 (IBpiers) Cbi.Account.CreateOrder: orderId='da15fe4022194b19b6bfc03dcd6c453e' account='Sim101' name='SET LONG' orderState=Initialized instrument='MES DEC23' orderAction=Buy orderType='Limit' limitPrice=4534 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=70 time='2023-11-17 08:02:47' gtd='2099-12-01' statementDate='2023-11-17' id=-1 comment=''
    2023-11-17 08:02:47:157 (IBpiers) Cbi.Account.Submit0: realOrderState=Initialized isPendingSubmit=False orderId='da15fe4022194b19b6bfc03dcd6c453e' account='Sim101' name='SET LONG' orderState=Initialized instrument='MES DEC23' orderAction=Buy orderType='Limit' limitPrice=4534 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=70 time='2023-11-17 08:02:47' gtd='2099-12-01' statementDate='2023-11-17'
    2023-11-17 08:02:47:162 (IBpiers) Cbi.Account.Submit1: realOrderState=Initialized orderId='da15fe4022194b19b6bfc03dcd6c453e' account='Sim101' name='SET LONG' orderState=Initialized instrument='MES DEC23' orderAction=Buy orderType='Limit' limitPrice=4534 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=70 time='2023-11-17 08:02:47' gtd='2099-12-01' statementDate='2023-11-17'
    2023-11-17 08:02:47:164 (IBpiers) Cbi.Simulator.Submit: realOrderState=Initialized orderId='da15fe4022194b19b6bfc03dcd6c453e' account='Sim101' name='SET LONG' orderState=Submitted instrument='MES DEC23' orderAction=Buy orderType='Limit' limitPrice=4534 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=70 time='2023-11-17 08:02:47' gtd='2099-12-01' statementDate='2023-11-17' delay=100
    2023-11-17 08:02:47:165 (IBpiers) Cbi.Account.OrderUpdateCallback: realOrderState=Submitted orderId='da15fe4022194b19b6bfc03dcd6c453e' account='Sim101' name='SET LONG' orderState=Submitted instrument='MES DEC23' orderAction=Buy limitPrice=4534 stopPrice=0 quantity=1 orderType='Limit' filled=0 averageFillPrice=0 time='2023-11-17 08:02:47' statementDate='2023-11-17' error=NoError comment='' nr=-1
    2023-11-17 08:02:47:473 (IBpiers) Cbi.Account.OrderUpdateCallback: realOrderState=Accepted orderId='da15fe4022194b19b6bfc03dcd6c453e' account='Sim101' name='SET LONG' orderState=Accepted instrument='MES DEC23' orderAction=Buy limitPrice=4534 stopPrice=0 quantity=1 orderType='Limit' filled=0 averageFillPrice=0 time='2023-11-17 08:02:47' statementDate='2023-11-17' error=NoError comment='' nr=-1
    2023-11-17 08:02:47:474 (IBpiers) Cbi.Account.OrderUpdateCallback: realOrderState=Working orderId='da15fe4022194b19b6bfc03dcd6c453e' account='Sim101' name='SET LONG' orderState=Working instrument='MES DEC23' orderAction=Buy limitPrice=4534 stopPrice=0 quantity=1 orderType='Limit' filled=0 averageFillPrice=0 time='2023-11-17 08:02:47' statementDate='2023-11-17' error=NoError comment='' nr=-1
    2023-11-17 08:02:47:772 (IBpiers) Cbi.Account.Change0: realOrderState=Working orderId='da15fe4022194b19b6bfc03dcd6c453e' account='Sim101' name='SET LONG' orderState=Working instrument='MES DEC23' orderAction=Buy orderType='Limit' limitPrice=4534 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=70 time='2023-11-17 08:02:47' gtd='2099-12-01' statementDate='2023-11-17' limitPriceChanged=4534 stopPriceChanged=0 quantityChanged=1

    2023-11-17 08:40:45:128 (IBpiers) Cbi.Simulator.Fill1: realOrderState=Working orderId='da15fe4022194b19b6bfc03dcd6c453e' maxFillQuantity=1 price=4534 thread=39
    2023-11-17 08:40:45:128 (IBpiers) Cbi.Simulator.Fill2: realOrderState=Working orderId='da15fe4022194b19b6bfc03dcd6c453e' fillQuantity=1 price=4534
    2023-11-17 08:40:45:131 (IBpiers) Cbi.Account.OrderUpdateCallback: realOrderState=Filled orderId='da15fe4022194b19b6bfc03dcd6c453e' account='Sim101' name='SET LONG' orderState=Filled instrument='MES DEC23' orderAction=Buy limitPrice=4534 stopPrice=0 quantity=1 orderType='Limit' filled=1 averageFillPrice=4534 time='2023-11-17 08:40:45' statementDate='2023-11-17' error=NoError comment='' nr=-1
    2023-11-17 08:40:45:275 (IBpiers) Cbi.Account.ExecutionUpdateCallback: executionId='5d9c1e11b22c43f1b1645af4e1a3fecb' account='Sim101' instrument='MES DEC23' exchange=Globex price=4534 quantity=1 marketPosition=Long operation=Add orderID='da15fe4022194b19b6bfc03dcd6c453e' isSod=False time='2023-11-17 08:40:45' statementDate='2023-11-17'
    2023-11-17 08:40:45:342 (IBpiers) Cbi.Account.PositionUpdateCallback: instrument='MES DEC23' account='Sim101' avgPrice=4534 quantity=1 marketPosition=Long operation=Add
    2023-11-17 08:40:45:355 NinjaScript.StrategyBase.CancelAllOrders: orderId='9fe8d36f9c1246d6b0dc8c03cce39572' account='Sim101' name='LONG STOPLOSS' orderState=Accepted instrument='MES DEC23' orderAction=Sell orderType='Stop Limit' limitPrice=4421.75 stopPrice=4426.75 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=69 time='2023-11-16 17:10:41' gtd='2099-12-01' statementDate='2023-11-16'
    2023-11-17 08:40:45:356 (IBpiers) Cbi.Account.Cancel0: realOrderState=Accepted orderId='9fe8d36f9c1246d6b0dc8c03cce39572' account='Sim101' name='LONG STOPLOSS' orderState=CancelPending instrument='MES DEC23' orderAction=Sell orderType='Stop Limit' limitPrice=4421.75 stopPrice=4426.75 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=69 time='2023-11-17 08:40:45' gtd='2099-12-01' statementDate='2023-11-17'
    2023-11-17 08:40:45:356 (IBpiers) Cbi.Account.OrderUpdateCallback: realOrderState=CancelPending orderId='9fe8d36f9c1246d6b0dc8c03cce39572' account='Sim101' name='LONG STOPLOSS' orderState=CancelPending instrument='MES DEC23' orderAction=Sell limitPrice=4421.75 stopPrice=4426.75 quantity=1 orderType='Stop Limit' filled=0 averageFillPrice=0 time='2023-11-17 08:40:45' statementDate='2023-11-17' error=NoError comment='' nr=-1
    2023-11-17 08:40:45:356 (IBpiers) Cbi.Account.Cancel1: realOrderState=CancelPending orderId='9fe8d36f9c1246d6b0dc8c03cce39572' account='Sim101' name='LONG STOPLOSS' orderState=CancelPending instrument='MES DEC23' orderAction=Sell orderType='Stop Limit' limitPrice=4421.75 stopPrice=4426.75 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=69 time='2023-11-17 08:40:45' gtd='2099-12-01' statementDate='2023-11-17'
    2023-11-17 08:40:45:358 (IBpiers) Cbi.Simulator.Cancel: realOrderState=CancelPending orderId='9fe8d36f9c1246d6b0dc8c03cce39572' account='Sim101' name='LONG STOPLOSS' orderState=CancelSubmitted instrument='MES DEC23' orderAction=Sell orderType='Stop Limit' limitPrice=4421.75 stopPrice=4426.75 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=69 time='2023-11-17 08:40:45' gtd='2099-12-01' statementDate='2023-11-17' delay=100
    2023-11-17 08:40:45:358 (IBpiers) Cbi.Account.OrderUpdateCallback: realOrderState=CancelSubmitted orderId='9fe8d36f9c1246d6b0dc8c03cce39572' account='Sim101' name='LONG STOPLOSS' orderState=CancelSubmitted instrument='MES DEC23' orderAction=Sell limitPrice=4421.75 stopPrice=4426.75 quantity=1 orderType='Stop Limit' filled=0 averageFillPrice=0 time='2023-11-17 08:40:45' statementDate='2023-11-17' error=NoError comment='' nr=-1
    2023-11-17 08:40:45:506 (IBpiers) Cbi.Account.OrderUpdateCallback: realOrderState=Cancelled orderId='9fe8d36f9c1246d6b0dc8c03cce39572' account='Sim101' name='LONG STOPLOSS' orderState=Cancelled instrument='MES DEC23' orderAction=Sell limitPrice=4421.75 stopPrice=4426.75 quantity=1 orderType='Stop Limit' filled=0 averageFillPrice=0 time='2023-11-17 08:40:45' statementDate='2023-11-17' error=NoError comment='' nr=5​
    It seems pretty normal to me. So I went to the guide NT8 looking for info and I found this:

    When starting a strategy on real-time data, the starting behavior will renew any active historical orders and resubmit these orders to your live or simulation account. This process includes updating the historical/backtest generated order ID to the account generated order ID, and any associated OCO IDs. If you are tracking order objects, is critical that you update the order reference to ensure that it is now using the correct order details.



    This should be done in OnOrderUpdate() to ensure all cases of order transitions are handled.
    Critical: If you DO NOT update a historical order reference, and then attempt to cancel/change that order after it has been submitted in real-time, your strategy will be disabled with a message similar to: "Strategy has been disabled because it attempted to modify a historical order that has transitioned to a live order."
    Tip: When the real-time order is submitted, there is a generic Order object passed into the OnOrderUpdate() method containing the live order details which can be used for debugging. It is recommended you use the helper GetRealtimeOrder() when your strategy transitions to real-time to update your order references
    I can't understand why if my Algo didn't submit any historical order, working with only real-time data, gives me this error message.

    - Can you give an example, how in NT8, should be updated the state of an order? I did it exactly like NT7 and it has worked so far.
    - Please, advise if I must use an additional method to OnOrderUpdate.

    Thanks

    #2
    Hello pstrusi,

    The warning that was produced would be due to a historical order object that was used when the strategy entered realtime. To know the specifics of what happened you could add prints into OnOrderUpdate and OnBarUpdate to see how the strategy runs when you enable it.

    To solve that warning you can use the code from the sample in the following page. You need to add some additional logic to OnOrderUpdate to handle transitioning order objects. Because you are using the unmanaged approach you would be working with order objects so this would be relevant to any unmanaged strategy that you are converting from nt7. This is also relevant in managed approach strategies if you use OnOrderUpdate and track orders using order objects.

    You need to add the following code for any order objects that you use:
    Code:
    if (myOrder != null && myOrder.IsBacktestOrder && State == State.Realtime)
    myOrder = GetRealtimeOrder(myOrder);​
    https://ninjatrader.com/support/help...ltimeorder.htm

    Comment


      #3
      Hi Jesse, thanks for the response.

      I understand your response. It's logic that if I had some historical orders when the Algo goes real-time, these orders need to be "converted" to real-time, but in my case wasn't like that. Still, I gonna add these additional lines of code.

      What really worries me is that in my case, the Algo went flat since opening yesterday 6pm under pure real-time data, and despite that, when an order got filled this morning under real-time data, the error pops up out of the blue. It wasn't any historical order, so it may repeat itself onnce again.

      Please note that and raise it to Dev's team. I'm sure that something is not right

      Thanks for the help

      Comment


        #4
        Hello pstrusi,

        As I don't know what logic you had used or the specifics of that situation all I can suggest is to add GetRealtimeOrder to ensure that does not happen again. That code is expected to be used anytime you are working with order objects. The warning you had seen happens only if you are using an order object that was marked historical and it would need to be converted to a realtime order object. This is a new part of working with orders which differs from NT7 so you will need to make sure you are using GetRealtimeOrder when you are using order objects in your code.

        Comment


          #5
          Once again, thanks Jesse for the useful suggestions.

          Have a good W.E

          Comment


            #6
            Originally posted by NinjaTrader_Jesse View Post
            Hello pstrusi,

            The warning that was produced would be due to a historical order object that was used when the strategy entered realtime. To know the specifics of what happened you could add prints into OnOrderUpdate and OnBarUpdate to see how the strategy runs when you enable it.

            To solve that warning you can use the code from the sample in the following page. You need to add some additional logic to OnOrderUpdate to handle transitioning order objects. Because you are using the unmanaged approach you would be working with order objects so this would be relevant to any unmanaged strategy that you are converting from nt7. This is also relevant in managed approach strategies if you use OnOrderUpdate and track orders using order objects.

            You need to add the following code for any order objects that you use:
            Code:
            if (myOrder != null && myOrder.IsBacktestOrder && State == State.Realtime)
            myOrder = GetRealtimeOrder(myOrder);​
            https://ninjatrader.com/support/help...ltimeorder.htm
            Thank you for the explanation. I ran into the same issue with my strategy. My strategy looks at past data and place limit orders for entry. When it transitions from backtest to live, i'd like to just cancel the backtest orders because on the next bar, it will calculate fresh where to put the limit orders in, and will start clean.
            Can you please let me know the easiest way to do this? Can I simply put some code in the OnStateChange method to say, if State == State.Realtime, then cancel all existing backtest orders and flatten the position? Is my reference to my backtest order still valid at that point?

            Comment


              #7
              Hello zehua,

              You would have to use a condition like the following to know when the last historical bar is processing from OnBarUpdate.

              if(CurrentBar == Count - 3)
              {

              }

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              109 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              59 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              37 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              40 views
              0 likes
              Last Post TheRealMorford  
              Started by Mindset, 02-28-2026, 06:16 AM
              0 responses
              78 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Working...
              X