• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order update events problem preventing OCO

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

    Order update events problem preventing OCO

    Hi guys,
    I'm having some problems with orders that are meant to be OCO. Basically what seems to be happening is that a stoploss is trailed, and virtually at the same time the target fills, which correctly cancels the stoploss order, but the trail command is still on its way and it puts on a new stoploss order for the position, causing an overfill on this trade.

    See screenshot of the trade.

    Here is output from the strategy, showing the events. I presume it is the new multi-threaded event driven nature of NT8 that is capable of this, so what I would like to get is a procedure that is not prone to this kind of behaviour.

    3/16/2017 7:43:28 AM trailing LS1 to 1228.8
    3/16/2017 7:43:30 AM Strategy 'dlSwingsStrategy/101134163': Entered internal SubmitOrderManaged() method at 3/16/2017 7:43:30 AM: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=2 LimitPrice=0 StopPrice=1228.8 SignalName='LS1' FromEntrySignal='LE1'
    OnOrderUpdate(): orderId='5b38bf9579a741af85f91388b10761ed' account='Sim101' name='LS1' orderState=ChangePending instrument='GC 04-17' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=1227.8 quantity=2 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=561 time='2017-03-16 07:43:30' gtd='2099-12-01' statementDate='2017-03-16'
    OnOrderUpdate(): orderId='5b38bf9579a741af85f91388b10761ed' account='Sim101' name='LS1' orderState=ChangeSubmitted instrument='GC 04-17' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=1228.8 quantity=2 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=561 time='2017-03-16 07:43:30' gtd='2099-12-01' statementDate='2017-03-16'
    3/16/2017 7:43:30 AM Strategy 'dlSwingsStrategy/101134163': Amended matching order at 3/16/2017 7:43:30 AM: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=2 LimitPrice=0 StopPrice=1228.8 SignalName='LS1' FromEntrySignal='LE1'
    3/16/2017 7:43:28 AM trailing LS2 to 1228.8
    3/16/2017 7:43:30 AM Strategy 'dlSwingsStrategy/101134163': Entered internal SubmitOrderManaged() method at 3/16/2017 7:43:30 AM: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=1228.8 SignalName='LS2' FromEntrySignal='LE2'
    OnOrderUpdate(): orderId='fa8ee9bcb60743febd0cdc48f76aa12d' account='Sim101' name='LS2' orderState=ChangePending instrument='GC 04-17' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=1227.8 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=563 time='2017-03-16 07:43:30' gtd='2099-12-01' statementDate='2017-03-16'
    OnOrderUpdate(): orderId='fa8ee9bcb60743febd0cdc48f76aa12d' account='Sim101' name='LS2' orderState=ChangeSubmitted instrument='GC 04-17' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=1228.8 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=563 time='2017-03-16 07:43:30' gtd='2099-12-01' statementDate='2017-03-16'
    3/16/2017 7:43:30 AM Strategy 'dlSwingsStrategy/101134163': Amended matching order at 3/16/2017 7:43:30 AM: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=1228.8 SignalName='LS2' FromEntrySignal='LE2'
    OnOrderUpdate(): orderId='a15537f8ae384841b48ff696da9ce467' account='Sim101' name='LT1' orderState=PartFilled instrument='GC 04-17' orderAction=Sell orderType='Limit' limitPrice=1229.1 stopPrice=0 quantity=2 tif=Gtc oco='' filled=1 averageFillPrice=1229.1 onBehalfOf='' id=562 time='2017-03-16 07:43:30' gtd='2099-12-01' statementDate='2017-03-16'
    OnOrderUpdate(): orderId='a15537f8ae384841b48ff696da9ce467' account='Sim101' name='LT1' orderState=Filled instrument='GC 04-17' orderAction=Sell orderType='Limit' limitPrice=1229.1 stopPrice=0 quantity=2 tif=Gtc oco='' filled=2 averageFillPrice=1229.1 onBehalfOf='' id=562 time='2017-03-16 07:43:30' gtd='2099-12-01' statementDate='2017-03-16'

    3/16/2017 7:43:30 AM Strategy '101134163/dlSwingsStrategy: Cancelled pending exit order, since associated position is closed, orderId='5b38bf9579a741af85f91388b10761ed' account='Sim101' name='LS1' orderState=ChangeSubmitted instrument='GC 04-17' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=1228.8 quantity=2 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=561 time='2017-03-16 07:43:30' gtd='2099-12-01' statementDate='2017-03-16'
    OnOrderUpdate(): orderId='5b38bf9579a741af85f91388b10761ed' account='Sim101' name='LS1' orderState=CancelPending instrument='GC 04-17' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=1228.8 quantity=2 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=561 time='2017-03-16 07:43:30' gtd='2099-12-01' statementDate='2017-03-16'
    OnOrderUpdate(): orderId='5b38bf9579a741af85f91388b10761ed' account='Sim101' name='LS1' orderState=CancelSubmitted instrument='GC 04-17' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=1228.8 quantity=2 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=561 time='2017-03-16 07:43:30' gtd='2099-12-01' statementDate='2017-03-16'

    OnOrderUpdate(): orderId='5b38bf9579a741af85f91388b10761ed' account='Sim101' name='LS1' orderState=Accepted instrument='GC 04-17' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=1228.8 quantity=2 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=561 time='2017-03-16 07:43:30' gtd='2099-12-01' statementDate='2017-03-16'

    OnOrderUpdate(): orderId='fa8ee9bcb60743febd0cdc48f76aa12d' account='Sim101' name='LS2' orderState=Accepted instrument='GC 04-17' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=1228.8 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=563 time='2017-03-16 07:43:30' gtd='2099-12-01' statementDate='2017-03-16'
    OnOrderUpdate(): orderId='5b38bf9579a741af85f91388b10761ed' account='Sim101' name='LS1' orderState=Working instrument='GC 04-17' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=1228.8 quantity=2 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=561 time='2017-03-16 07:45:55' gtd='2099-12-01' statementDate='2017-03-16'
    OnOrderUpdate(): orderId='fa8ee9bcb60743febd0cdc48f76aa12d' account='Sim101' name='LS2' orderState=Working instrument='GC 04-17' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=1228.8 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=563 time='2017-03-16 07:45:55' gtd='2099-12-01' statementDate='2017-03-16'
    OnOrderUpdate(): orderId='5b38bf9579a741af85f91388b10761ed' account='Sim101' name='LS1' orderState=Filled instrument='GC 04-17' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=1228.8 quantity=2 tif=Gtc oco='' filled=2 averageFillPrice=1228.8 onBehalfOf='' id=561 time='2017-03-16 07:45:55' gtd='2099-12-01' statementDate='2017-03-16'
    3/16/2017 7:45:55 AM Strategy '101134163/dlSwingsStrategy: Cancelled pending exit order, since associated position is closed, orderId='fa8ee9bcb60743febd0cdc48f76aa12d' account='Sim101' name='LS2' orderState=Working instrument='GC 04-17' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=1228.8 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=563 time='2017-03-16 07:45:55' gtd='2099-12-01' statementDate='2017-03-16'
    OnOrderUpdate(): orderId='fa8ee9bcb60743febd0cdc48f76aa12d' account='Sim101' name='LS2' orderState=CancelPending instrument='GC 04-17' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=1228.8 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=563 time='2017-03-16 07:45:55' gtd='2099-12-01' statementDate='2017-03-16'
    OnOrderUpdate(): orderId='fa8ee9bcb60743febd0cdc48f76aa12d' account='Sim101' name='LS2' orderState=CancelSubmitted instrument='GC 04-17' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=1228.8 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=563 time='2017-03-16 07:45:55' gtd='2099-12-01' statementDate='2017-03-16'
    OnOrderUpdate(): orderId='5b38bf9579a741af85f91388b10761ed' account='Sim101' name='LS1' orderState=Cancelled instrument='GC 04-17' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=1228.8 quantity=2 tif=Gtc oco='' filled=2 averageFillPrice=1228.8 onBehalfOf='' id=561 time='2017-03-16 07:45:55' gtd='2099-12-01' statementDate='2017-03-16'
    OnOrderUpdate(): orderId='fa8ee9bcb60743febd0cdc48f76aa12d' account='Sim101' name='LS2' orderState=Cancelled instrument='GC 04-17' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=1228.8 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=563 time='2017-03-16 07:45:55' gtd='2099-12-01' statementDate='2017-03-16'

    Cheers,
    saltminer

    #2
    Hello saltminer,

    Thank you for your post.

    You would need to implement logic to not adjust the order if the order is in a Cancel state.

    Are you using Order objects in your code? Are you utilizing OnOrderUpdate()?
    Where are you making the adjustment of the protective orders? (In what function?)

    I look forward to your response.
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      Hi,
      the trailing stop code is executed in OnBarUpdate(). I am indeed using Order objects and utilising OnOrderUpdate(). In the printout below you can see each OnOrderUpdate event.
      If you scan the printout, you will see at the very top that OnBarUpdate() decides to trail the stop at 7:43:28. It does this to two orders, LS1 and LS2. That seems to go fine.

      Then the red text shows that target LT1 has been filled, and LS1 correctly gets cancelled.

      After that red text the LS1 that should remain cancelled comes to life again, as if the the outgoing request to change an order and the incoming cancellation of it didn't ever get together over a beer to discuss the state of things.

      The trailing stop command was given PRIOR to any knowledge that NT had about a target being hit, so it would seem correct and unavoidable to do that at that moment. Hence, my request for advice.

      Cheers,
      saltminer

      Comment


        #4
        Hello saltminer,

        Thank you for your patience.

        I see what you mean here. I am unable to recreate this behavior as it is not expected.

        Please send me your log and trace files so that I may look into what occurred.

        You can do this by going to the Control Center-> Help-> Email Support.

        Please list 'ATTN: Patrick H' in the subject line and reference this thread in the body of the email.

        I look forward to your response.
        Patrick H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by MarianApalaghiei, Today, 12:21 PM
        0 responses
        0 views
        0 likes
        Last Post MarianApalaghiei  
        Started by williamzz, Today, 11:37 AM
        1 response
        7 views
        0 likes
        Last Post Emma1
        by Emma1
         
        Started by thecashguys, Today, 10:18 AM
        0 responses
        6 views
        0 likes
        Last Post thecashguys  
        Started by pjsmith, Today, 09:58 AM
        0 responses
        9 views
        0 likes
        Last Post pjsmith
        by pjsmith
         
        Started by bebbus, Today, 09:13 AM
        0 responses
        6 views
        0 likes
        Last Post bebbus
        by bebbus
         
        Working...
        X