• 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

Changing partially filled stop order creates order in other direction

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

    Changing partially filled stop order creates order in other direction

    Hello,

    I had a extrange case where a stop order was filled in multiple lots. My code automatically adjust stop orders to the current share number because I also have at the same time profit limit orders therefore decreasing the number of shares in the current position. Where there were about 94 shares left I executed an order change and instead I end up with a buy order in IB.
    Unfortunatelly I did not save the log from NinjaTrader but I have the log I generated from my code in TS plus the audit trail from IB that shows the partial filled orders plus the new order in the other direction. Here I am pasting my trace and IB audit trail.

    Thanks,
    Moscu

    MY TRACE
    1) Stop Order sent
    400 , SHR= 400 , PRVSHR= 0 , ORD=SELL-35.45-35.34-400
    10/10/2008 , 1006 , 1 , 10:06:42 AM , 35.53 , PLACE , BUY-SX H StopLoss-T35-1006-1-STOP-35.59 , SX H StopLoss ,ORD=BUY-35.59-0.00-400 , MP=-1 , RTN=0
    2) Order partially filled
    10/10/2008 , 1007 , 29 , 10:07:13 AM , 35.62 , WAITING , BUY-SX H StopLoss-T35-1006-1-STOP-35.59, status=PartFilled , MP= -1 Fill-Price= 35.62 , Filled= 306 , SHR= 400 , PRVSHR= 400 , ORD=BUY-35.59-0.00-400
    10/10/2008 , 1007 , 30 , 10:07:13 AM , 35.62 , WAITING , BUY-SX H StopLoss-T35-1006-1-STOP-35.59, status=PartFilled , MP= -1 Fill-Price= 35.62 , Filled= 306 , SHR= 400 , PRVSHR= 400 , ORD=BUY-35.59-0.00-400
    10/10/2008 , 1007 , 31 , 10:07:13 AM , 35.62 , WAITING , BUY-SX H StopLoss-T35-1006-1-STOP-35.59, status=PartFilled , MP= -1 Fill-Price= 35.62 , Filled= 306 , SHR= 400 , PRVSHR= 400 , ORD=BUY-35.59-0.00-400
    3) Change sent when lest 94 shares to be filled.
    10/10/2008 , 1007 , 32 , 10:07:14 AM , 35.63 , CHANGE , BUY-SX H StopLoss-T35-1006-1-STOP-35.59 , SX H StopLoss ,ORD=BUY-35.63-0.00-94 , MP=-1 , RTN=0
    4) confirmation received from NInja for 94 shares
    10/10/2008 , 1007 , 32 , 10:07:14 AM , 35.63 , FILLED , BUY-SX H StopLoss-T35-1006-1-STOP-35.59, status=Filled , MP= -1 Fill-Price= 35.63 , Filled= 400 , SHR= 94 , PRVSHR= 400 , ORD=BUY-35.63-0.00-94

    IB Audit trail
    1) Place stop order
    PlaceOrder 20081010-14:06:34 2147439180.0 - Buy 400 PRU Stop - DAY AuxPrice= 35.59; Account= *******; StopPrice= 35.59; 6115 = 0; OptionAcct= c; DdeId= 3605; ServerId= 0; SecurityType= CS; SecurityID= PRU; SecurityIDSource= 101; ContractMultiplier= 1.0; 6436 = 0; ExDestination= BEST; 6210 = BEST; ContractID= 13865082; EOrder= Socket; Currency= USD; 6211 = ; 6238 = ;
    Acknowledged 20081010-14:07:04 2147439180.0 00044338.00011385.48eede60.0001 Buy 400 PRU Stop - DAY ExecID= 70533.1223647624.0; ExecType= New; ExecTransType= Status; OrdStatus= New; 6210 = BEST; AuxPrice= 35.59; StopPrice= 35.59; CumQty= 0; LeavesQty= 400; AvgPx= 0; SecurityType= CS; ClearingFirm= 534; Account= *******; ConQPath= PRU/STK/USD/13865082/33556/ARCA/26/PRU/PRU; TransactTime= 20081010-14:07:04; DdeId= 3605; Rule80A= AgenySingleOrder; ContractID= 13865082; Currency= USD; Exchange= BEST; 6116 = 0; OptionAcct= c; CustomerOrFirm= Customer; WorkingIndicator: Y; 6205 = 1; 6434 = 0; 6115 = 0; EOrder= Socket; 6419 = IB;
    Acknowledged 20081010-14:07:04 2147439180.0 00044338.00011385.48eede60.0001 Buy 400 PRU Stop - DAY ExecID= 70533.1223647624.1; ExecType= New; ExecTransType= New; OrdStatus= New; ExDestination= NYSE; SecurityExchange= NYSE; AuxPrice= 35.59; CumQty= 0; LeavesQty= 400; AvgPx= 0; SecurityType= CS; Account= *******; ConQPath= PRU/STK/USD/13865082/33556/ARCA/26/PRU/PRU; TransactTime= 20081010-14:07:04; DdeId= 3605; OptionAcct= c; CustomerOrFirm= Customer;

    2) Order partial Filled starts
    PartiallyFilled 20081010-14:07:05 2147439180.0 00044338.00011385.48eede60.0001 Buy 100 PRU Stop - DAY ExecID= 0001f028.48ef68e3.01.01; ExecType= PartiallyFilled; ExecTransType= New; OrdStatus= PartiallyFilled; ExDestination= NYSE; SecurityExchange= NYSE; AuxPrice= 35.59; LastMarket= NYSE; CumQty= 100; LeavesQty= 300; AvgPx= 35.61; SecurityType= CS; ClearingFirm= 534; Account= *******; ConQPath= PRU/STK/USD/13865082/33556/NYSE/26/PRU/PRU; TransactTime= 20081010-14:07:05; DdeId= 3605; ContractID= 13865082; Currency= USD; OptionAcct= c; CustomerOrFirm= Customer; EOrder= Socket; 6419 = IB;
    PartiallyFilled 20081010-14:07:05 2147439180.0 00044338.00011385.48eede60.0001 Buy 6 PRU Stop - DAY ExecID= 0000d3fc.48ef6341.01.01; ExecType= PartiallyFilled; ExecTransType= New; OrdStatus= PartiallyFilled; ExDestination= BATS; SecurityExchange= BATS; AuxPrice= 35.59; LastMarket= BATS; CumQty= 106; LeavesQty= 294; AvgPx= 35.61; SecurityType= CS; ClearingFirm= 534; Account= *******; ConQPath= PRU/STK/USD/13865082/33556/BATS/26/PRU/PRU; TransactTime= 20081010-14:07:05; DdeId= 3605; ContractID= 13865082; Currency= USD; OptionAcct= c; CustomerOrFirm= Customer; EOrder= Socket; 6419 = IB;
    PartiallyFilled 20081010-14:07:05 2147439180.0 00044338.00011385.48eede60.0001 Buy 100 PRU Stop - DAY ExecID= 0000d3fc.48ef6342.01.01; ExecType= PartiallyFilled; ExecTransType= New; OrdStatus= PartiallyFilled; ExDestination= BATS; SecurityExchange= BATS; AuxPrice= 35.59; LastMarket= BATS; CumQty= 206; LeavesQty= 194; AvgPx= 35.6149; SecurityType= CS; ClearingFirm= 534; Account= *******; ConQPath= PRU/STK/USD/13865082/33556/BATS/26/PRU/PRU; TransactTime= 20081010-14:07:05; DdeId= 3605; ContractID= 13865082; Currency= USD; OptionAcct= c; CustomerOrFirm= Customer; EOrder= Socket; 6419 = IB;
    PartiallyFilled 20081010-14:07:05 2147439180.0 00044338.00011385.48eede60.0001 Buy 100 PRU Stop - DAY ExecID= 0000da5f.48ef431c.01.01; ExecType= PartiallyFilled; ExecTransType= New; OrdStatus= PartiallyFilled; ExDestination= ISLAND; SecurityExchange= ISLAND; AuxPrice= 35.59; LastMarket= ISLAND; CumQty= 306; LeavesQty= 94; AvgPx= 35.6165; SecurityType= CS; ClearingFirm= 534; Account= *******; ConQPath= PRU/STK/USD/13865082/33556/ISLAND/26/PRU/PRU; TransactTime= 20081010-14:07:05; DdeId= 3605; ContractID= 13865082; Currency= USD; OptionAcct= c; CustomerOrFirm= Customer; EOrder= Socket; 6419 = IB;
    PartiallyFilled 20081010-14:07:05 2147439180.0 00044338.00011385.48eede60.0001 Buy 0 PRU Stop - DAY ExecID= 70533.1223647625.0; ExecType= PartiallyFilled; ExecTransType= Status; OrdStatus= PartiallyFilled; ExDestination= ISLAND; SecurityExchange= ISLAND; 6210 = BEST; AuxPrice= 35.59; StopPrice= 35.59; CumQty= 306; LeavesQty= 94; AvgPx= 35.6165; SecurityType= CS; ClearingFirm= 534; Account= *******; ConQPath= PRU/STK/USD/13865082/33556/ARCA/26/PRU/PRU; TransactTime= 20081010-14:07:05; DdeId= 3605; Rule80A= AgenySingleOrder; ContractID= 13865082; Currency= USD; Exchange= BEST; 6116 = 0; OptionAcct= c; CustomerOrFirm= Customer; WorkingIndicator: Y; 6205 = 1; 6434 = 0; 6115 = 0; EOrder= Socket; 6419 = IB;
    3) here the order was filled by IB with the total of 400
    Filled 20081010-14:07:06 2147439180.0 00044338.00011385.48eede60.0001 Buy 94 PRU Stop 35.69 DAY ExecID= 00012c64.48ef1cd5.01.01; ExecType= Filled; ExecTransType= New; OrdStatus= Filled; ExDestination= ARCA; SecurityExchange= ARCA; AuxPrice= 35.59; LastMarket= ARCA; CumQty= 400; LeavesQty= 0; AvgPx= 35.6338; SecurityType= CS; ClearingFirm= 534; Account= *******; ConQPath= PRU/STK/USD/13865082/33556/ARCA/26/PRU/PRU; TransactTime= 20081010-14:07:06; DdeId= 3605; ContractID= 13865082; Currency= USD; OptionAcct= c; CustomerOrFirm= Customer; EOrder= Socket; 6419 = IB;

    4)Here the order change comes as a buy order into IB
    PlaceOrder 20081010-14:07:05 2147439181.0 - Buy 94 PRU Stop - DAY AuxPrice= 35.68; Account= *******; StopPrice= 35.68; 6115 = 0; OptionAcct= c; DdeId= 3606; ServerId= 0; SecurityType= CS; SecurityID= PRU; SecurityIDSource= 101; ContractMultiplier= 1.0; 6436 = 0; ExDestination= BEST; 6210 = BEST; ContractID= 13865082; EOrder= Socket; Currency= USD; 6211 = ; 6238 = ;
    Acknowledged 20081010-14:07:07 2147439181.0 00044338.00011385.48eede66.0001 Buy 94 PRU Stop - DAY ExecID= 70533.1223647627.0; ExecType= New; ExecTransType= Status; OrdStatus= New; 6210 = BEST; AuxPrice= 35.68; StopPrice= 35.68; CumQty= 0; LeavesQty= 94; AvgPx= 0; SecurityType= CS; ClearingFirm= 534; Account= *******; ConQPath= PRU/STK/USD/13865082/33556/ARCA/26/PRU/PRU; TransactTime= 20081010-14:07:07; DdeId= 3606; Rule80A= AgenySingleOrder; ContractID= 13865082; Currency= USD; Exchange= BEST; 6116 = 0; OptionAcct= c; CustomerOrFirm= Customer; WorkingIndicator: Y; 6205 = 1; 6434 = 0; 6115 = 0; EOrder= Socket; 6419 = IB;
    Filled 20081010-14:07:07 2147439181.0 00044338.00011385.48eede66.0001 Buy 94 PRU Stop 35.68 DAY ExecID= 0000d3fc.48ef6345.01.01; ExecType= Filled; ExecTransType= New; OrdStatus= Filled; ExDestination= BATS; SecurityExchange= BATS; AuxPrice= 35.68; LastMarket= BATS; CumQty= 94; LeavesQty= 0; AvgPx= 35.68; SecurityType= CS; ClearingFirm= 534; Account= *******; ConQPath= PRU/STK/USD/13865082/33556/BATS/26/PRU/PRU; TransactTime= 20081010-14:07:07; DdeId= 3606; ContractID= 13865082; Currency= USD; OptionAcct= c; CustomerOrFirm= Customer; EOrder= Socket; 6419 = IB;
    Last edited by moscu; 10-14-2008, 09:43 PM.

    #2
    Sorry,

    It looked like I place the order because the market position did not change quick enough after the order was filled. This is a problem that has been posted in another thread. Please disregard this post.
    Moscu

    Comment


      #3
      to avoid this problem after i send an order i instruct tradestation code to wait 3 seconds, this gives NT enough time for NTmarketPosition to update in real-time.

      if it takes longer than 3 seconds for previous order to get filled or rejected, i use OrderStatus() function to make sure we wait the extra time. once orderstatus = filled or rejected, we can then safely check NTmarketPosition.

      if you need to place orders really fast then you can just use OrderStatus() to wait until orderstatus() returns filled, partfilled or rejected, and when this happens you can then execute your tradestation block of code where the buy and sell conditions are located. I am assuming that when OrderStatus() returns a string such as filled, partfilled or rejected, this means that NTmarketPosition has already updated to reflect its true value. this should stop unwanted orders from being placed.

      please see my solution in this thread http://www.ninjatrader-support.com/v...ead.php?t=9983 which makes sure OrderStatus returns a string called "initialized" straight after an order is placed.

      hope this helps someone else.

      rocket
      Last edited by Rocket130713; 10-15-2008, 03:02 AM.

      Comment


        #4
        This need to be fix

        rocket
        I came across the problem with the empty NtStatus while testing a scalping strategy that will send an order and if not filled within 10 ticks it will cancel the order. What I found is that the status at times was NULL. In this case the actual cancel takes place but then after that you never get a return from NtStatus just the empty string. What I am doing now is testing for NTStatus to be different than NULL before I make any changes to the order. While this fixes my problem for now it is a problem with the strategy because the order stays out there longer than I want to. NT most fix this two problems soon.
        1) Always return a status from NTStatus.
        2) Never return empty when an order was cancel before it is initialized.

        Moscu

        Comment


          #5
          maybe you could assign a variable called Order_State to a string called "CancelSubmitted" straight after you actually cancel the order. and also set the same variable to "initialized" straight after you send an order. then at the top of your code you could say if OrderStatus() does not equal a string called "CancelSubmitted" or "initialized" or "" then set Order_State to OrderStatus(). this should mean that the variable you created called Order_State always returns a string and never an empty string. Note that "" refered to above = empty string. also you would need to initialize Order_State variable as an empty string at the start of your code, so Order_State starts off as an empty string.

          if you do the above, then when you place an order and call OrderStatus() you should get a string that changes from "Initialized" to "PendingSubmit" to "Accepted" to "Working" to "Filled".

          if you cancel an order, OrderStatus() should return a string that changes from "CancelSubmitted" to "PendingCancel" to "Cancelled".

          Im fairly sure that this will solve your problem.

          rocket.
          Last edited by Rocket130713; 10-17-2008, 01:31 AM.

          Comment


            #6
            Rocket130713,

            Thanks for you suggestion I have something similar that I believe it has solved the problem. My trading environment is very complex. I have charts loaded with multiple strategies trading the same symbol in mulitple time frames. As you can see all this has to be synchronize. I finally managed to get this complex system of strategies to work scalping the market. I am using something similar to what you suggest but in this case I am using the empty string as state "order-sent-waiting-reply". Whenever I sent an order I set a "timer" whether in ticks or bars, this is the waiting time for the order to be filled. If the order is not filled during that time I sent a cancel order. I keep monitoring the order because after 9 months working with this API I found most of the gotchas. Here are some scenarios that can happen.

            1) The order has been filled. No problem here you get Filled from NTStatus
            2) The order is submitted to IB and returns an order id to NT. In this case the order is cancelled. Cancelled returned from NTStatus
            3) The order has not been submitted to IB yet and NT removes it without creating a status. Empty string is returned here. It can be handled.
            4) The connection is lost IB is lost. There is no way to tell when it is comming back. This is a nightmare situation.

            For 3 and 4 as I mention are a problem. My goal is to have a hands off system as much as possible. Those two situations can leave you with a loose order with no stop. The safest way is to keep polling, that will solve case 4. I am not sure about case 3, it could also leave an orphan filled order.

            One solution is to create some code that runs in IB and alerts you when there is an open position with no stop exit order. I plan to work on this one in the near future. This way I could have my dream system that can run without much supervision.

            Moscu

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by rwilliam, Today, 03:14 PM
            0 responses
            3 views
            0 likes
            Last Post rwilliam  
            Started by rwilliam, Today, 03:10 PM
            1 response
            4 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by rontronimous, Today, 03:04 PM
            2 responses
            5 views
            0 likes
            Last Post rontronimous  
            Started by zacharydw00, Today, 03:14 PM
            0 responses
            3 views
            0 likes
            Last Post zacharydw00  
            Started by junkone, 09-12-2019, 07:10 PM
            11 responses
            82 views
            0 likes
            Last Post cnecorp
            by cnecorp
             
            Working...
            X