Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CancelOrder...

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

    #31
    Hello Mark,

    Thank you for your time and patience.

    While testing and working to create an example script that cancels an order via a timer, I considered that the issue might be with historical orders that are transitioned to real-time because a timer would not work on historical processing. This was not the underlying cause of the behavior, though I did want to point it out as a reminder. Timers only work in real time and are not able to be backtested.

    What I did find is that CancelOrder() is successful when IsLiveUntilCancelled is true in the order method that submits the order. Otherwise, if it is set to its default value of false, the order is only canceled when the entry condition expires. I have reported this to the development team for further investigation. I will post an update here once I have one.

    With that said, if you change your order method to the overload that allows you to set IsLiveUntilCancelled to true, you should see your orders being canceled as expected:
    EnterLongLimit(0, true, 1, GetCurrentBid() - (TickSize * 6), orderSignalName);

    For more information about live until cancelled orders:
    https://ninjatrader.com/support/help...tm#LiveUntilCa ncelledOrders

    For working samples demonstrating CancelOrder() both with and without a timer and demonstrated with the managed and unmanaged approaches, please see the attached strategies.

    KonstantinosNT please check out the attached examples. You mentioned, "I have sometimes been in the position to wanting to Cancel a specific Order, just a few seconds after my Strategy made it, but I haven't achieved that yet." If you have an example of output that demonstrates a cancellation that was not completed as expected, we would be glad to further investigate. It is important to keep in mind the following notes from the CancelOrder() page in the help guide:
    1.This method sends a cancel request to the broker and does not guarantee that an order is completely cancelled. Most of the time you can expect your order to come back 100% cancelled.

    2.An order can be completely filled or part filled in the time that you send the cancel request and the time the exchange receives the request. Check the OnOrderUpdate() method for the state of an order you attempted to cancelled.



    Thank you again for your patience and please let me know if I may be of further assistance.
    Attached Files

    Comment


      #32
      Originally posted by NinjaTrader_Emily View Post
      With that said, if you change your order method to the overload that allows you to set IsLiveUntilCancelled to true, you should see your orders being canceled as expected: EnterLongLimit(0, true, 1, GetCurrentBid() - (TickSize * 6), orderSignalName);
      Thanks Emily. I will make the change and resume testing.

      In a strategy, where is "TimeInForce = TimeInForce.Gtc;" applied?

      Cheers,

      Mark

      Next day: Verified using the overloaded methods for EnterLongLimit and EnterShortLimit that require the IsLiveUntilCancelled boolean parameter does allow the order to be cancelled via CancelOrder for live data on the simulator. I have not tried live with a broker, yet.
      Last edited by Mark--; 03-09-2023, 09:02 PM.

      Comment


        #33
        Hello Emily,

        Changing the parameter IsLiveUntilCancelled to the boolean value: true will result to the Order being active beyond the end of the current bar,
        sitting there active and waiting for an explicit Cancel Order from my side to get cancelled. Should I don’t cancel it, that Order will stay there forever
        ready to get filled at any random moment !

        That’s wrong to me. It’s not what I need.
        I don’t want to change my Strategy’s functionality that way.

        I want my sent Order to continue expiring normally at the end of the current bar.
        I just want the added capability to Cancel my Order before the end of the current bar (and of course before it get filled, if I get to) if my Strategy’s logic
        decides that the Market conditions got against my Order, immediately after that specific Order had released.

        If a Cancel Order doesn’t release automatically from my Strategy’s side, then I want my (unfilled) Order to expire normally at the end of the current bar,
        without any further action from my side.

        My wish and my request to NT Support is to have the above added capability available.

        Comment


          #34
          Originally posted by Mark-- View Post

          Thanks Emily. I will make the change and resume testing.

          In a strategy, where is "TimeInForce = TimeInForce.Gtc;" applied?

          Cheers,

          Mark

          Next day: Verified using the overloaded methods for EnterLongLimit and EnterShortLimit that require the IsLiveUntilCancelled boolean parameter does allow the order to be cancelled via CancelOrder for live data on the simulator. I have not tried live with a broker, yet.
          Hello Mark,

          Thank you for your patience.

          I apologize for the delayed response; I had only seen your post before the edit that added the question about TimeInForce. TimeInForce is a property that will set the time in force (TIF) for all of the orders that are generated by the strategy. It is set in OnStateChange and applied to all orders for that strategy. For more information, please see the help guide page here:


          Please let me know if I may be of further assistance.

          Comment


            #35
            Originally posted by KonstantinosNT View Post
            Hello Emily,

            Changing the parameter IsLiveUntilCancelled to the boolean value: true will result to the Order being active beyond the end of the current bar,
            sitting there active and waiting for an explicit Cancel Order from my side to get cancelled. Should I don’t cancel it, that Order will stay there forever
            ready to get filled at any random moment !

            That’s wrong to me. It’s not what I need.
            I don’t want to change my Strategy’s functionality that way.

            I want my sent Order to continue expiring normally at the end of the current bar.
            I just want the added capability to Cancel my Order before the end of the current bar (and of course before it get filled, if I get to) if my Strategy’s logic
            decides that the Market conditions got against my Order, immediately after that specific Order had released.

            If a Cancel Order doesn’t release automatically from my Strategy’s side, then I want my (unfilled) Order to expire normally at the end of the current bar,
            without any further action from my side.

            My wish and my request to NT Support is to have the above added capability available.

            Hello KonstantinosNT,

            Thank you for your patience.

            I understand that setting IsLiveUntilCancelled to true is not ideal in all scenarios. I offered this suggestion as a workaround to get CancelOrder() to function as expected for the time being while we investigate what is happening with CancelOrder() on orders that have IsLiveUntilCancelled set to false. As I previously mentioned in my post, "I have reported this to the development team for further investigation. I will post an update here once I have one."

            I certainly understand that there are use cases, such as yours, where you would like to have your bars use the default behavior where they expire and automatically cancel at the end of a bar. We are looking into the cause of orders not responding to CancelOrder() if they have the default behavior and I will follow up here in this thread once I have more information from the development team.

            I sincerely appreciate your patience.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Yesterday, 05:17 AM
            0 responses
            54 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            131 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            73 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            44 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            49 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X