Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CancelOrder() Doesn't work!!!

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

    CancelOrder() Doesn't work!!!

    Here's the proof.

    I am using an Unmanaged approach

    I went short and created an associated pending stop loss. I then close the position using the code below

    CancelOrder(shortOrder); NinjaTrader.Gui.SuperDom.SuperDom.FlattenEverythin g();

    The Flatten everything is like a fail safe and also stops the running of the strategy so that I can pinpoint the area in the trace where it happened. The trace is below.

    You can see that the CancelOrder comes in but is NEVER filled. ( see filled=0 )
    Filled=1 pertains to the "FlattenEverything"




    Cbi.Connection.ProcessEventArgs.OrderStatusEventAr gs: Order='536cbdf896694b7b9a85ed4ac207dd0d/Replay101' Name='Average Fill..Stop loss to protect short' New state=PendingCancel Instrument='GC 12-14' Action=BuyToCover Limit price=1146.4 Stop price=1146.4 Quantity=1 Type=StopLimit Filled=0 Fill price=0 Error=NoError Native error=''
    2014-11-21 19:53:20:643 (Market Replay Connection) Cbi.Order.Update1: oldid='536cbdf896694b7b9a85ed4ac207dd0d' Order='536cbdf896694b7b9a85ed4ac207dd0d/Replay101' Name='Average Fill..Stop loss to protect short' New state=PendingCancel Instrument='GC 12-14' Action=BuyToCover Limit price=1146.4 Stop price=1146.4 Quantity=1 Type=StopLimit Filled=0 Fill price=0 Error=NoError Native error=''
    2014-11-21 19:53:20:643 (Market Replay Connection) Cbi.Connection.ProcessEventArgs.OrderStatusEventAr gs: Order='536cbdf896694b7b9a85ed4ac207dd0d/Replay101' Name='Average Fill..Stop loss to protect short' New state=Cancelled Instrument='GC 12-14' Action=BuyToCover Limit price=1146.4 Stop price=1146.4 Quantity=1 Type=StopLimit Filled=0 Fill price=0 Error=NoError Native error=''
    2014-11-21 19:53:20:643 (Market Replay Connection) Cbi.Order.Update1: oldid='536cbdf896694b7b9a85ed4ac207dd0d' Order='536cbdf896694b7b9a85ed4ac207dd0d/Replay101' Name='Average Fill..Stop loss to protect short' New state=Cancelled Instrument='GC 12-14' Action=BuyToCover Limit price=1146.4 Stop price=1146.4 Quantity=1 Type=StopLimit Filled=0 Fill price=0 Error=NoError Native error=''
    2014-11-21 19:53:20:727 (Market Replay Connection) Cbi.Position.Close0: closeWithMarket=False quantity=1 Instrument='GC 12-14 Nymex' Type=Ask Price=1146.6 Volume=1 Time=07/11/2014 13:31:19
    2014-11-21 19:53:20:727 (Market Replay Connection) Cbi.Position.Close6: closeWithMarket
    2014-11-21 19:53:20:727 (Market Replay Connection) Cbi.Position.Close11: totalSize=0 quantity=1
    2014-11-21 19:53:20:729 (Market Replay Connection) Cbi.Connection.ProcessEventArgs.OrderStatusEventAr gs: Order='03f860111e924c21a5a0aabd276e8c9b/Replay101' Name='Close' New state=Initialized Instrument='GC 12-14' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error=''
    2014-11-21 19:53:20:729 (Market Replay Connection) Cbi.Order.Update1: oldid='03f860111e924c21a5a0aabd276e8c9b' Order='03f860111e924c21a5a0aabd276e8c9b/Replay101' Name='Close' New state=Initialized Instrument='GC 12-14' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error=''
    2014-11-21 19:53:20:729 (Market Replay Connection) Cbi.Order.Submit: Order='03f860111e924c21a5a0aabd276e8c9b/Replay101' Name='Close' State=Initialized Instrument='GC 12-14' Action=Buy Limit price=0 Stop price=0 Quantity=1 Strategy='(null)' Type=Market Tif=Day Oco='' Filled=0 Fill price=0 Token='f1fdcfc68d6e40188f5e6d1528e52946' Gtd='01/12/2099 00:00:00'
    2014-11-21 19:53:20:729 (Market Replay Connection) Cbi.Simulator.Submit: Order='03f860111e924c21a5a0aabd276e8c9b/Replay101' Name='Close' State=Initialized Instrument='GC 12-14' Action=Buy Limit price=0 Stop price=0 Quantity=1 Strategy='(null)' Type=Market Tif=Day Oco='' Filled=0 Fill price=0 Token='f1fdcfc68d6e40188f5e6d1528e52946' Gtd='01/12/2099 00:00:00'
    2014-11-21 19:53:20:730 (Market Replay Connection) Cbi.Connection.ProcessEventArgs.OrderStatusEventAr gs: Order='f1fdcfc68d6e40188f5e6d1528e52946/Replay101' Name='Close' New state=PendingSubmit Instrument='GC 12-14' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error=''
    2014-11-21 19:53:20:730 (Market Replay Connection) Cbi.Order.Update1: oldid='03f860111e924c21a5a0aabd276e8c9b' Order='f1fdcfc68d6e40188f5e6d1528e52946/Replay101' Name='Close' New state=PendingSubmit Instrument='GC 12-14' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error=''
    2014-11-21 19:53:20:730 (Market Replay Connection) Cbi.Connection.ProcessEventArgs.OrderStatusEventAr gs: Order='f1fdcfc68d6e40188f5e6d1528e52946/Replay101' Name='Close' New state=Accepted Instrument='GC 12-14' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error=''
    2014-11-21 19:53:20:730 (Market Replay Connection) Cbi.Order.Update1: oldid='f1fdcfc68d6e40188f5e6d1528e52946' Order='f1fdcfc68d6e40188f5e6d1528e52946/Replay101' Name='Close' New state=Accepted Instrument='GC 12-14' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error=''
    2014-11-21 19:53:20:730 (Market Replay Connection) Cbi.Connection.ProcessEventArgs.OrderStatusEventAr gs: Order='f1fdcfc68d6e40188f5e6d1528e52946/Replay101' Name='Close' New state=Working Instrument='GC 12-14' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error=''
    2014-11-21 19:53:20:730 (Market Replay Connection) Cbi.Order.Update1: oldid='f1fdcfc68d6e40188f5e6d1528e52946' Order='f1fdcfc68d6e40188f5e6d1528e52946/Replay101' Name='Close' New state=Working Instrument='GC 12-14' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error=''
    2014-11-21 19:53:20:730 (Market Replay Connection) Cbi.Simulator.Fill1: id='f1fdcfc68d6e40188f5e6d1528e52946' maxFillQuantity=1 price=1146.6
    2014-11-21 19:53:20:731 (Market Replay Connection) Cbi.Simulator.Fill2: id='f1fdcfc68d6e40188f5e6d1528e52946' fillQuantity=1 price=1146.6
    2014-11-21 19:53:20:731 (Market Replay Connection) Cbi.Simulator.FillNow: id='f1fdcfc68d6e40188f5e6d1528e52946' state='Working' instrument='GC 12-14' quantity=1 filled=0 price=1146.6
    2014-11-21 19:53:20:731 (Market Replay Connection) Cbi.Connection.ProcessEventArgs.OrderStatusEventAr gs: Order='f1fdcfc68d6e40188f5e6d1528e52946/Replay101' Name='Close' New state=Filled Instrument='GC 12-14' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=1 Fill price=1146.6 Error=NoError Native error=''
    2014-11-21 19:53:20:731 (Market Replay Connection) Cbi.Order.Update1: oldid='f1fdcfc68d6e40188f5e6d1528e52946' Order='f1fdcfc68d6e40188f5e6d1528e52946/Replay101' Name='Close' New state=Filled Instrument='GC 12-14' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=1 Fill price=1146.6 Error=NoError Native error=''
    2014-11-21 19:53:20:731 (Market Replay Connection) Cbi.Connection.ProcessEventArgs.ExecutionUpdateEve ntArgs: Execution='59d99d93db204ee9bb09215cebf5c67d' Instrument='GC 12-14' Account='Replay101' Exchange=Default Price=1146.6 Quantity=1 Market position=Long Operation=Insert Order='f1fdcfc68d6e40188f5e6d1528e52946' Time='07/11/2014 13:31:19'
    2014-11-21 19:53:20:731 (Market Replay Connection) Cbi.Connection.ProcessEventArgs.ExecutionUpdateEve ntArgs2: executionId='59d99d93db204ee9bb09215cebf5c67d' entry=False exit=True position=0 multiplier=1 rate=1 sod=False
    2014-11-21 19:53:20:732 (Market Replay Connection) Cbi.Connection.ProcessEventArgs.PositionUpdateEven tArgs1: Instrument='GC 12-14' Account='Replay101' Avg price=1146.6 Quantity=0 Market position=Short Operation=Remove Currency=Unknown

    #2
    A canceled order would not be filled since it canceled.

    Cancel order does not nullify an order object, nor does it manage your position. The only thing CancelOrder() will do is submit cancel request to your brokerage, which will attempt to cancel the order. Your traces you provide show order's canceling, so if you can please fill me in on what you expected to happen, I'll be happy to offer clarification.

    While we're on the topic, I feel it should be worth mentioning that a CancelOrder() method will submit an *attempt* to cancel the order. It's completely possible that an order can be filled on the brokerage servers before your cancel request is sent, which would in turn prevent the order from being canceled


    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. 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.
    MatthewNinjaTrader Product Management

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    646 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    367 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    108 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    569 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    573 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X