Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Strategy 'XXX' has been disabled because it attempted to modify a historical

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

    Strategy 'XXX' has been disabled because it attempted to modify a historical

    Title:Strategy 'XXX' has been disabled because it attempted to modify a historical order that has transitioned to a live order.

    Hello,

    i got this error-Message in a MessageBox and in the Output Window.
    Checking google i will found this side from Ninjatrader:
    https://ninjatrader.com/support/help...storicaltolive

    perfect solution, i put this in my Strategy and i get following error:
    Strategy 'XXX' has been disabled because it attempted to modify a historical order that has transitioned to a live order.

    Here is my Code:

    protected override void OnBarUpdate()
    {
    ......
    FastOrders.Add(EnterLongLimit(0, true, 1, validPrice, "UniqueName"));
    ........
    }

    protected override void OnStateChange()
    {
    if (State == State.Terminated)
    {
    Print("isTerminated == true");
    foreach (Order o in FastOrders)
    {
    Print(Closes[BarsInProgress].Bars.GetTime(CurrentBar).ToString("yyyy_MM_dd_HH_ mm_ss") + " " + this.Name + "-Terminated Fast CancelOrder(" + o.Name + ") ID: " + o.Id);
    CancelOrder(GetRealtimeOrder(o));
    }
    FastOrders.Clear();

    foreach (Order o in SlowOrders)
    {
    Print(Closes[BarsInProgress].Bars.GetTime(CurrentBar).ToString("yyyy_MM_dd_HH_ mm_ss") + " " + this.Name + "-Terminated Slow CancelOrder(" + o.Name + ") ID: " + o.Id);
    CancelOrder(GetRealtimeOrder(o));
    }
    SlowOrders.Clear();
    isTerminated = true;
    Print("isTerminated == false");
    }
    }


    output Window:
    Enabling NinjaScript strategy 'xxx/233462606' : On starting a real-time strategy - StartBehavior=ImmediatelySubmit Position=BTCEUR 12L AccountPosition=BTCEUR 49L EntryHandling=All entries EntriesPerDirection=200 StopTargetHandling=By strategy position ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=False SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On price change IsUnmanaged=False MaxRestarts=4 in 5 minutes
    NinjaScript strategy 'xxx/233462606' submitting order
    NinjaScript strategy 'xxx/233462606' submitting order
    NinjaScript strategy 'xxx/233462606' submitting order
    NinjaScript strategy 'xxx/233462606' submitting order
    NinjaScript strategy 'xxx/233462606' submitting order
    NinjaScript strategy 'xxx/233462606' submitting order
    NinjaScript strategy 'xxx/233462606' submitting order
    2021_12_03_01_00_00
    xxx-OnOrderUpdate Long_Slow_00003 ID 8304 order.OrderState: Filled
    2021_12_03_01_00_00
    xxx-OnExecutionUpdate
    2021_12_03_01_00_00
    xxx-OnExecutionUpdate OrderFilled: Long_Slow_00003
    2021_12_03_01_00_00
    xxx-Create_EnterShortLimit: fullQuantity: 25 current_TakeProfit: 24210,94
    Strategy 'xxx/233462606' 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.
    isTerminated == true
    2021_12_03_01_00_00
    xxx-Terminated Fast CancelOrder(Long_Fast_00010) ID: -1
    2021_12_03_01_00_00
    xxx-Terminated Fast CancelOrder(Long_Fast_00011) ID: -1
    2021_12_03_01_00_00
    xxx-Terminated Slow CancelOrder(Long_Slow_00000) ID: -1
    2021_12_03_01_00_00
    xxx-Terminated Slow CancelOrder(Long_Slow_00001) ID: -1
    2021_12_03_01_00_00
    xxx-Terminated Slow CancelOrder(Long_Slow_00002) ID: -1
    2021_12_03_01_00_00
    xxx-Terminated Slow CancelOrder(Long_Slow_00004) ID: -1
    isTerminated == false
    Disabling NinjaScript strategy 'xxx/233462606'


    This OnStateChange will be called to late?
    Whats happening here?

    with best regards
    Spike

    #2
    Hello Spike,

    Thanks for your message.

    The important part to consider with Order objects is that we will need to transition the Order object from historical (virtual) to any realtime existing orders.

    In OnStateChange, under State == State.Realtime, we would check if the Order object is not null (if there is an Order object, which would have been assigned during historical processing)

    and if the Order object is not null, we would then give the Order object to GetRealtimeOrder() and then assign the result back to the Order object.

    GetRealtimeOrder would only be used in OnStateChange when State == State.Realtime, and we should have conditions set up to transition every Order object from historical to realtime, because any one of the Order objects in the script could be get into this scenario.

    Our SampleOnOrderUpdate strategy provides a good demonstration of using Order objects, and also with transitioning them to realtime.

    SampleOnOrderUpdate - https://ninjatrader.com/support/help...and_onexec.htm

    We look forward to assisting.

    JimNinjaTrader Customer Service

    Comment


      #3
      He Jim,

      Thank you for your answer and the hint with dan SampleOnOrderUpdate.
      I knew this one.

      As you in my Log file see, i get the error-Message bevore OnStateChanged called.
      So, this is a nice hint, but i doesn't help.
      As you see in my Code sample, i use this code you describe.

      Best regards
      Spike

      Comment


        #4
        Hello Spike,

        You are using GetRealtimeOrder in other states than State.Realtime. Only use it in OnStateChange when State == State.Realtime.

        Also keep in mind that as the strategy dialog gets opened and the strategy gets configured, there is a cloning process, and State.SetDefaults and State.Terminated will be seen before the "running instance" of the strategy, where we reach State.DataLoaded, State.Historical, and State.Realtime.

        NinjaScript LifeCycle - https://ninjatrader.com/support/help...fecycle_of.htm

        OnStateChange - https://ninjatrader.com/support/help...tatechange.htm
        JimNinjaTrader Customer Service

        Comment


          #5
          Hi Jim,

          I got this error too, when the chart is only in history.
          From 01.Dez.2021 to 03.Dez.2021 i get the error at finishing the last bar.
          not only from historical to "real" realtime.

          wbr
          Spike

          Comment


            #6
            Hi Jim,

            Thank you for this two Links.

            I have this error since an week, an i tried everything i found. And you are right, State.Terminated is the wrong state.
            I changed them to Realtime and i didn't get the error. I also get the Canceld-Messages. But the Order are not Canceld.
            After canceling the Orders, they get Working again.
            Enabling NinjaScript strategy 'XXX/233462601' : On starting a real-time strategy - StartBehavior=ImmediatelySubmit Position=BTCEUR 2L EntryHandling=All entries EntriesPerDirection=200 StopTargetHandling=By strategy position ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=False SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On price change IsUnmanaged=False MaxRestarts=4 in 5 minutes
            NinjaScript strategy 'XXX/233462601' submitting order
            NinjaScript strategy 'XXX/233462601' submitting order
            NinjaScript strategy 'XXX/233462601' submitting order
            NinjaScript strategy 'XXX/233462601' submitting order
            NinjaScript strategy 'XXX/233462601' submitting order
            NinjaScript strategy 'XXX/233462601' submitting order
            NinjaScript strategy 'XXX/233462601' submitting order
            NinjaScript strategy 'XXX/233462601' submitting order
            Realtime == true
            2021_11_09_01_00_00 XXX-Terminated Fast CancelOrder(Long_Fast_00002) ID: -1
            2021_11_09_01_00_00 XXX-Terminated Fast CancelOrder(Long_Fast_00003) ID: -1
            2021_11_09_01_00_00 XXX-Terminated Slow CancelOrder(Long_Slow_00000) ID: -1
            2021_11_09_01_00_00 XXX-Terminated Slow CancelOrder(Long_Slow_00001) ID: -1
            2021_11_09_01_00_00 XXX-Terminated Slow CancelOrder(Long_Slow_00002) ID: -1
            2021_11_09_01_00_00 XXX-Terminated Slow CancelOrder(Long_Slow_00003) ID: -1
            2021_11_09_01_00_00 XXX-Terminated Slow CancelOrder(Long_Slow_00004) ID: -1
            Realtime == false
            2021_11_09_01_00_00 XXX-OnOrderUpdate Long_Slow_00001 ID 8372 order.OrderState: Filled
            2021_11_09_01_00_00 XXX-OnOrderUpdate ExitLongLimit_426 ID 8376 order.OrderState: CancelPending
            2021_11_09_01_00_00 XXX-OnOrderUpdate ExitLongLimit_426 ID 8376 order.OrderState: CancelSubmitted
            2021_11_09_01_00_00 XXX-OnOrderUpdate ExitLongLimit_426 ID 8376 order.OrderState: CancelSubmitted
            2021_11_09_01_00_00 XXX-OnOrderUpdate ExitLongLimit_426 ID 8376 order.OrderState: Working
            2021_11_09_01_00_00 XXX-OnOrderUpdate Long_Fast_00002 ID 8377 order.OrderState: CancelPending
            2021_11_09_01_00_00 XXX-OnOrderUpdate Long_Fast_00002 ID 8377 order.OrderState: CancelSubmitted
            2021_11_09_01_00_00 XXX-OnOrderUpdate Long_Fast_00002 ID 8377 order.OrderState: CancelSubmitted
            2021_11_09_01_00_00 XXX-OnOrderUpdate Long_Fast_00002 ID 8377 order.OrderState: Working
            2021_11_09_01_00_00 XXX-OnOrderUpdate Long_Fast_00003 ID 8378 order.OrderState: CancelPending
            2021_11_09_01_00_00 XXX-OnOrderUpdate Long_Fast_00003 ID 8378 order.OrderState: CancelSubmitted
            2021_11_09_01_00_00 XXX-OnOrderUpdate Long_Fast_00003 ID 8378 order.OrderState: CancelSubmitted
            2021_11_09_01_00_00 XXX-OnOrderUpdate Long_Fast_00003 ID 8378 order.OrderState: Working
            2021_11_09_01_00_00 XXX-OnOrderUpdate Long_Slow_00002 ID 8373 order.OrderState: Cancelled
            2021_11_09_01_00_00 XXX-OnOrderUpdate Long_Slow_00003 ID 8374 order.OrderState: Cancelled
            2021_11_09_01_00_00 XXX-OnOrderUpdate ExitLongLimit_426 ID 8376 order.OrderState: Cancelled
            2021_11_09_01_00_00 XXX-OnOrderUpdate Long_Fast_00002 ID 8377 order.OrderState: Cancelled
            2021_11_09_01_00_00 XXX-OnOrderUpdate Long_Slow_00004 ID 8375 order.OrderState: Cancelled
            2021_11_09_01_00_00 XXX-OnOrderUpdate Long_Fast_00003 ID 8378 order.OrderState: Cancelled


            protected override void OnBarUpdate()
            {
            ...
            if (isRealtime)
            {
            // this line is not in the log.
            Print(Closes[BarsInProgress].Bars.GetTime(CurrentBar).ToString("yyyy_MM_dd_HH_ mm_ss") + " " + this.Name + "-OnBarUpdate isRealtime " + BarsRequiredToTrade + "-" + CurrentBar);
            return;
            }
            ...
            }

            protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
            {
            try
            {
            Print(" " + Closes[BarsInProgress].Bars.GetTime(CurrentBar).ToString("yyyy_MM_dd_HH_ mm_ss") + " " + this.Name + "-OnOrderUpdate " + order.Name + " ID " + order.Id + " order.OrderState: " + order.OrderState);

            if (isRealtime)
            return;
            ....
            }

            The OnStateChange-code hasn't changed, only to State.Realtime



            Can you help me, why this orders are working again?

            The Starting question is solved.

            lg
            Spike

            Comment


              #7
              Hello Spike,

              If this is a separate inquiry from the original, it would be best to open a new thread. (This helps for the forum to be searchable by others, and to help our technicians step in in case another technician is out of the office.)

              I'm having trouble understanding what the issue at hand is. I don't see any errors with what is provided, and I am unsure of what is happening that is unexpected or what you are expecting to happen. When I look at your logs I see the orders reach Cancelled at the end of your OnOrderUpdate output. Are the orders not cancelled?

              Could you prepare a small test script that has only what is necessary to display the issue following some steps, and could you further describe what you are expecting to see, and what you see that is not expected?

              I look forward to hearing from you.

              JimNinjaTrader Customer Service

              Comment


                #8
                Hi Jim,

                i will open a new thread. it seems to be logic.

                thanks for your help.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by d122y, Today, 10:20 AM
                1 response
                4 views
                0 likes
                Last Post NinjaTrader_ChrisL  
                Started by trader3000a, Today, 06:41 AM
                1 response
                10 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by slimcactus, Today, 10:26 AM
                0 responses
                5 views
                0 likes
                Last Post slimcactus  
                Started by trader3000a, Today, 09:23 AM
                2 responses
                9 views
                0 likes
                Last Post trader3000a  
                Started by CharlieBoy, Today, 08:37 AM
                1 response
                6 views
                0 likes
                Last Post NinjaTrader_JustinD  
                Working...
                X