Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unmanaged Orders Issue: Cancelled Orders Getting Executed

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

    Unmanaged Orders Issue: Cancelled Orders Getting Executed

    I'm experiencing an issue with unmanaged orders in my trading strategy. During real-time execution, the strategy places an order, cancels it, but the order still gets executed. This issue didn't occur during backtesting.

    Details:
    - The strategy places an order at approximately line 3,000 of the code.
    - The order is cancelled at around line 3,700.
    - The strategy concludes and code execution ends at around line 5,000.
    - Despite cancellation, the order is executed in real-time, but never in backtesting.
    - This issue has occurred multiple times with different orders and logic, and I've verified it through debugging.

    The orders are cancelled using the following code:
    CancelOrder(orderABC);
    orderABC = null;

    Has anyone else encountered this issue? Any insights or suggestions would be greatly appreciated.​

    Thanks.

    #2
    Hello remorim,

    Thank you for your post.

    Can you please provide output demonstrating the issue?

    Set TraceOrders to true in State.Configure, print the order object in OnOrderUpdate(), and print the Execution object from OnExecutionUpdate().

    TraceOrders will output to the NinjaScript Output window a message when orders are being submitted, ignored, cancelled, or rejected.

    Printing the order object in OnOrderUpdate() will allow you to track the progression of the order from submitted, to working, to filled, cancelled, or rejected.

    Printing the execution object in OnExecutionUpdate() will allow you to track the executed orders.

    TraceOrders - https://ninjatrader.com/support/help...raceorders.htm
    OnOrderUpdate() - https://ninjatrader.com/support/help...rderupdate.htm
    OnExecutionUpdate() - https://ninjatrader.com/support/help...tionupdate.htm

    Comment


      #3
      Thank you for your input! I've implemented the suggestions.

      Unfortunately, the event has already passed and become historical, so I'll have to wait for the next random occurrence to
      gather more data.

      I'll follow up and share my findings once I have more information.

      Comment


        #4
        This event just occured.

        I have attached the output data and control center's execeution tab data.

        At 12/27/2024 1:20:00 PM the strategy initiated an order "REVERSE-TRADE" but cancelled it before concluding its logic processing.
        -----------------------------
        //Simplified code excerpt
        CancelOrder(en1); en1 = null;
        en1 = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Market, Position.Quantity*2, 0, 0, "", "REVERSE-TRADE");
        ...
        ...
        ...

        CancelOrder(en1); en1 = null;
        CancelOrder(en2); en2 = null;
        CancelOrder(en2); en2 = null;

        CancelOrder(ex1); ex1 = null;
        ex1 = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Market, Position.Quantity, 0, 0, "", "EXIT-EMERGENCY-STOP");​
        ...​
        -----------------------------
        This order was executed in real-time.

        NT did generate an error about a possible overfill.

        Why did this order slip through?

        Is there a way to ensure cancelled orders are not executed?

        Thanks.


        Attached Files

        Comment


          #5
          Hello,

          This output is missing the info from TraceOrders and OnExecutionUpdate. Do you have a version of the output that includes this info?

          It's also not clear from the output that a cancelled order was indeed filled.

          I see an order called 'REVERSE-TRADE' was canceled, but there is no associated output with this order indicating it was then filled or executed.

          Comment


            #6
            Hello,

            For the last report I was using a different strategy that didn't include printouts and tracing. The event has occurred again, and I am attaching the details to this reply.
            The order "BUY-BIG-DROP-FVG" was cancelled by the strategy but was executed.

            Thanks,
            Attached Files

            Comment


              #7
              Hello remorim,

              I'm not seeing from the output that this order was filled.

              1/7/2025 1:10:00 PM Strategy 'testStrategy/346156203': Cancelled custom managed order: orderId='NT-00084-428' account='xxxxxxx' name='BUY-BIG-DROP-FVG' orderState=Working instrument='MNQ MAR25' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=6 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2025-01-07 13:10:00' gtd='2099-12-01' statementDate='2025-01-07'

              Time[0]: 1/7/2025 1:10:00 PM - OnOrderUpdate: orderId='NT-00084-428' account='xxxxxxx' name='BUY-BIG-DROP-FVG' orderState=CancelPending instrument='MNQ MAR25' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=6 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2025-01-07 13:10:00' gtd='2099-12-01' statementDate='2025-01-07'

              Time[0]: 1/7/2025 1:10:00 PM - OnOrderUpdate: orderId='NT-00084-428' account='xxxxxxx' name='BUY-BIG-DROP-FVG' orderState=CancelSubmitted instrument='MNQ MAR25' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=6 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2025-01-07 13:10:00' gtd='2099-12-01' statementDate='2025-01-07'

              Time[0]: 1/7/2025 1:10:00 PM - OnOrderUpdate: orderId='NT-00084-428' account='xxxxxxx' name='BUY-BIG-DROP-FVG' orderState=Cancelled instrument='MNQ MAR25' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=6 tif=Gtc oco='' filled=0​

              There is no further output indicating that this specific order was indeed filled after being cancelled. What is leading you to believe this order was executed after being cancelled? Does the Orders tab of the Control Center indicate this position was executed or is it showing it as Cacnelled (your screenshot shows the Executions tab)? The orders in your screenshot look like two seperate orders (1 for 1 quantity, then 1 for 5 quantity) while the output is showing an instance of 1 order submitted for 6 quantity.

              Are you running more than one instance of the same strategy?

              It may be best if you write into support with your log and trace so we can look into this further.
              Last edited by NinjaTrader_Gaby; 01-07-2025, 02:35 PM.

              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