Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order submitting twice in order state

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

    Order submitting twice in order state

    Below is my log file, I just curious why the cancel will happens twice for exitlong1
    11/18/21 12:52 Order Received order in unknown state 'Cancellation Failed', Order Id '48374984'
    11/18/21 12:52 Order Order='48374984/***' Name='Exit Long 1' New state='Cancelled' Instrument='NQ 12-21' Action='Sell' Limit price=16448.75 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='Unable to cancel order' Native error='Send cancels only after 30 secs. More cancels within this period will lead to logoff/disable of this user.'
    11/18/21 12:52 Order Received unknown order type '', Order Id '48374984'
    11/18/21 12:52 Order Order='48374984/***' Name='Exit Long 1' New state='Cancelled' Instrument='NQ 12-21' Action='Sell' Limit price=16448.75 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    11/18/21 12:52 Order Order='7b759212a8604624806561ce25adb3d0/***' Name='Sell' New state='Submitted' Instrument='NQ 12-21' Action='Sell short' Limit price=16439.75 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    11/18/21 12:52 Order Order='48374984/***' Name='Exit Long 1' New state='Cancel submitted' Instrument='NQ 12-21' Action='Sell' Limit price=16448.75 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    11/18/21 12:52 Order Order='48374984/***' Name='Exit Long 1' New state='Cancel submitted' Instrument='NQ 12-21' Action='Sell' Limit price=16448.75 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    11/18/21 12:52 Execution Execution='68641:M:11470252TN0244083|48375045|6826 876237077' Instrument='NQ 12-21' Account='***' Exchange=Globex Price=16439.75 Quantity=1 Market position=Short Operation=Operation_Add Order='48375045' Time='11/18/2021 12:52 PM'
    11/18/21 12:52 NinjaScript NinjaScript strategy 'aaMAllBarStrategy02/233514812' submitting order
    11/18/21 12:52 Order Order='48375045/***' Name='Stop Long' New state='Filled' Instrument='NQ 12-21' Action='Sell' Limit price=16439.75 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='' Filled=1 Fill price=16439.75 Error='No error' Native error=''
    11/18/21 12:52 Position Instrument='NQ 12-21' Account='***' Average price=16440 Quantity=1 Market position=Flat Operation=Remove
    11/18/21 12:52 Order Order='48375045/***' Name='Stop Long' New state='Working' Instrument='NQ 12-21' Action='Sell' Limit price=16439.75 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    11/18/21 12:52 Order Order='48375045/***' Name='Stop Long' New state='Accepted' Instrument='NQ 12-21' Action='Sell' Limit price=16439.75 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    11/18/21 12:52 Order Order='40f885d938dd4ca1820f080f5d435f78/***' Name='Stop Long' New state='Submitted' Instrument='NQ 12-21' Action='Sell' Limit price=16439.75 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    Let me explain what my code is doing.

    When the stoplong is happens and state is filled, then it will cancel the exitlong1.

    In my strategy (OnExecutionUpdate), i write

    Code:
    if (execution.Order==stopLong && stopLong != null)
    {
       if (stopLong.OrderState == OrderState.Filled)
    {
    if (exitLong1 != null && cancelexitLong1fromstoplong == 0)
    {
    CancelOrder(exitLong1);
    cancelexitLong1fromstoplong = 1;
    }
    
    }
    }
    I even do a extra int varaible to make sure it only run 1 times, but seem like it is nothing help.

    In my strategy (OnOrderUpdate), i write
    Code:
    if ( (order.OrderState == OrderState.Cancelled && order.Filled == 0) || order.OrderState == OrderState.Rejected || (order.OrderState == OrderState.Cancelled && order.Filled > 0) )
    {
    exitLong1 = null;
    exitLongQuantity1 = 0;
    
    }

    Any help from this ??
    Or I should not call the "cancelorder" inside the state.filled ??
    Last edited by NinjaTrader_Jim; 11-19-2021, 11:13 AM. Reason: Redacted account number

    #2
    Are you using Managed mode?
    Are you using SetStopLoss?
    Are you using SetProfitTarget?

    -=o=-

    May be because when the Stop is hit, NinjaTrader knows
    to automatically cancel the Target order?

    May be your cancelling of the Target order is not really
    necessary (because NinjaTrader already did it), and so
    your code is causing the duplicate entry you see?

    Answers to the top 3 questions would help answer the
    others ...

    -=o=-

    Looks like your log file in your post is copy/pasted from
    the Log tab, meaning the newest events are at the top,
    and older events are at the bottom.

    After the 2nd cancel order for the target, only one of the
    Cancel requests succeeds (this is your green highlight), and
    the other cancel request results in a UnableToCancelOrder
    error, with a warning from your broker.

    It appears your broker is a bit pissed at the duplicate cancel
    order request.

    Make sense?

    Comment


      #3
      I am using SubmitOrderUnmanaged

      This is the order flow :
      1) Entrylong will execute
      2) ExitLong1 will also execute once entrylong filled. (normally it will in state.working as the price not yet reach)
      3) Then once the stoplong appear, it will execute the stoplong and cancel the exitlong1

      Comment


        #4
        Are you submitting your stop and target orders in OnExecutionUpdate
        when the entry order fills or partial fills?

        Do you setup the stop and target orders as OCO orders?

        I'm trying to suggest that NinjaTrader is cancelling the target order
        automatically, due to an OCO situation dictated by when the stop order
        fills -- making your explicit cancel target order a duplicate.

        I'm suggesting,
        Either you have setup a OCO situation, or you have two explicit calls
        to CancelOrder happening in your code in very quick succession.

        Are either of these situations a possibility?

        If you say 'no', my next suggestion is that post a lot more code so
        we can see exactly what you're doing.

        -=o=-

        How much experience do you have with Unmanaged mode programming?

        Who is your broker?
        Last edited by bltdavid; 11-19-2021, 04:34 AM.

        Comment


          #5
          Originally posted by cincai View Post
          This is the order flow :
          1) Entrylong will execute
          2) ExitLong1 will also execute once entrylong filled. (normally it will in state.working as the price not yet reach)
          3) Then once the stoplong appear, it will execute the stoplong and cancel the exitlong1
          Sorry, this is not very clear.

          There is no order state called 'execute'.

          Can you rephrase the above order flow in exact terms,
          using only OrderState changes?

          If that exercise doesn't help you realize the problem, you may
          need to post more of your OnExecutionUpdate, and perhaps
          your OnOrderUpdate, too.

          Have you tried using TraceOrders?
          Last edited by bltdavid; 11-19-2021, 04:35 AM.

          Comment


            #6
            Hello cincai,

            Thanks for your post.

            I had edited it to remove your account number.

            I do not have full details to give a clear answer, but I can share some insight.

            Somethings that I notice:
            • It looks like you are using a Rithmic connection, but this is at best a hypothesis (Rithmic does not have native OCO handling, so OCO related cancels would be triggered from NinjaTrader instead of the broker's order routing server)
            • It does not look like you are using OCO with your orders as I do not see an OCO id with the order submission messages. Are you using OCO id's with SubmitOrderUnmanaged?
            • You mention you are using Unmanaged, so aside from OCO related cancels, I would expect all cancels to originate from CancelOrder or similar.
            Can you reproduce the multiple cancel messages with Playback?

            If so, you can add a print next to wherever you call CancelOrder to confirm where the cancels are originating.

            If you cannot reproduce with Playback, you could consider making a custom debug log using a StreamWriter to note where and when CancelOrder is getting called. When the matter happens trading live, you could then use the log to pinpoint where in your code the specific CancelOrder(s) are being called, and how often.

            Using a StreamWriter example - https://ninjatrader.com/support/help...o_write_to.htm

            We may be able to give a more detailed analysis if we receive the actual log and trace files. You may send those to me at scriptingauppoty [at] ninjatrader [dot] com with the text "Attn Jim 3362094" with a link to this thread.

            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
            126 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