Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Double positions switching sides running live w/ profit targets

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

    Double positions switching sides running live w/ profit targets

    I've had a couple of occurrences over the past 2 weeks of getting a double position while switching sides running live against IB. After spending some time going through both my output and the trace file, I think I know what is happening.

    Today's scenario was as follows.
    1. On 3/31, I went long 450 shares of [email protected]. A profit target of 2 ATR, or 69.88, was set.
    2. Today (4/2), at 2:10 PM, my strategy switched sides. Instead of being short 450 shares, I was short 900 shares. A profit target of 2 ATR, or 64.39, was set.

    Reading the trace file, I think that the very first thing that happens in this sequence is that the profit target is modified to the new price, but the type (e.g. sell to buy) is not changed. Here is the line:

    2008-04-02 14:10:11:249 (IB) IB.OrderRequest.Send: tmOrderId='574568958' orderId ='4709' instrument='IYR' expiry='' strikePrice=0 right='' exchange='SMART' action='SELL' limitPrice=64.39 auxPrice=0 quantity=450 type='LMT' tif='GTC' oca='NT-00084'

    This order gets filled right away (with several fills like this one):

    2008-04-02 14:10:11:391 (IB) IB.ExecutionsRequest.Process: id='00011f47.47f37e4e.01.01' instrument='IYR' orderid='574568958' account='XXXXXXXXX' filled=100 price=68.96 side='SLD' permId='574568958' liquidation=0

    Afterwards, I see the 'Close position' and 'Sell short' orders get processed, but I have already gotten fills on this symbol as shown above.

    This does not happen when running against the simulator.

    I have the trace file if you need the whole thing. I am running without profit targets for the time being as I suspect they are the cause.

    This is still on beta 10 as I did not notice release 1 was out until after the market opened.

    #2
    Sorry, not sure I follow.

    - you have a (long) position with no target (and no stop) set
    - you cross over by EnterMarket at 450 shares
    - you end up with 900 shares short instead of 450?
    - a profit target for these 900 shares is set?

    I suggest using TraceOrders to understand what's going on.

    Comment


      #3
      Dierk, I have already have trace orders on and have reviewed the output. I am simply doing an EnterShort() while already long and ending up with twice as many shares as I should.

      Like I said, I think there is a bug related to how NT is handling the profit target which is causing this.

      Comment


        #4
        Let me try to understand:
        - you have no profit target on the original position?
        - you have a profit target on the crossed over position?

        On the TraceOrders: Do you see that duplicate orders/signals are generated?

        Comment


          #5
          I would refer to the log file (tab) and take a look at exactly what orders are being filled when you double up.

          For example -

          Is -

          - Target getting filled
          - Close position order (name of the internal generated order) getting filled
          - A new entry order as well?

          If you can confirm what is filled we would have a better idea what is happening.
          RayNinjaTrader Customer Service

          Comment


            #6
            Dierk: I had profit targets in both directions. IMO the original long profit target order was modified, instead of cancelled and resubmitted, which left it as a sell and not a buy.

            Ray: Here are the orders and fills from the log. They are in time order, e.g. the opposite order from what you would see in the log tab. There is no way a profit target for a short order should be Sell, but you can see that is exactly what is happening. The price was modified from 69.88 (the long side profit) to 64.39 (the short side profit), but since the order was a sell, it executed right away. The price was ~68.97 at the time.

            4/2/2008 14:10 Order Order='574568958/XXXXXXX' Name='Profit target' New State=PendingChange Instrument='IYR' Action=Sell Limit price=64.39 Stop price=0 Quantity=450 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''

            4/2/2008 14:10 Order Order='6ada7bb124f84d74b3b99e0af19c313a/XXXXXXX' Name='Close position' New State=PendingSubmit Instrument='IYR' Action=Sell Limit price=0 Stop price=0 Quantity=450 Type=Market Filled=0 Fill price=0 Error=NoError Native error=''

            4/2/2008 14:10 Order Order='f08b656001a244409fef10f024ca5eb6/XXXXXXX' Name='Sell short' New State=PendingSubmit Instrument='IYR' Action=SellShort Limit price=0 Stop price=0 Quantity=450 Type=Market Filled=0 Fill price=0 Error=NoError Native error=''

            4/2/2008 14:10 Order Order='574568958/XXXXXXX' Name='Profit target' New State=Filled Instrument='IYR' Action=Sell Limit price=64.39 Stop price=0 Quantity=450 Type=Limit Filled=450 Fill price=68.95 Error=NoError Native error=''

            4/2/2008 14:10 Order Order='574568966/XXXXXXX' Name='Close position' New State=Filled Instrument='IYR' Action=Sell Limit price=0 Stop price=0 Quantity=450 Type=Market Filled=450 Fill price=68.95 Error=NoError Native error=''

            4/2/2008 14:10 Order Order='574568967/XXXXXXX' Name='Sell short' New State=Filled Instrument='IYR' Action=SellShort Limit price=0 Stop price=0 Quantity=450 Type=Market Filled=450 Fill price=68.95 Error=NoError Native error=''

            Comment


              #7
              Are you using liveUntilCancelled orders?

              Simple demonstration of problem -

              - Long 1
              - Live target limit order working to sell
              - You issue a ExitShort()
              - This generates two orders, one to close position another to open short
              - All three orders get filled (maybe target limit was very close to inside market etc...)

              This is rare but can happen and is on our list to resolve with NT7 since it has complex implications.

              How to work around?

              - Modify target to fill, then on next bar issue enter short or;
              - Use live untilCancelled order, cancel the target, wait for cancel confirmation in OnOrderStatus(), once received submit the EnterShort()
              RayNinjaTrader Customer Service

              Comment


                #8
                No, and the price was such that there was no chance of a race condition here.

                Comment


                  #9
                  To clarify, here is what I see -

                  - Your strategy modified the limit sell from from 69.88 to 64.39 which was below market and then filled
                  - Your strategy submitted EnterShort() in the same second which submitted two more sell orders, one to close the long position and the second to open a new short position

                  Is this correct?
                  RayNinjaTrader Customer Service

                  Comment


                    #10
                    No, my strategy is not modifying the profit target after it is set, under any conditions.

                    I believe the NT order management layer is modifying the profit target incorrectly as I switch sides instead of cancelling the old (long) one and creating a new (short) one.

                    This all happens as a result of submitting an EnterShort/SetProfitTarget pair after one EnterLong/SetProfitTarget pair.

                    Comment


                      #11
                      I see.

                      I can't think of a situation where this could happen but we will double check our code. What I would need from you is a TraceOrders = true output when this situation occurs. This will at least tell me when this order change occurs meaning, does it occur before the EnterShort() method is called. You can send the trace orders output to Dierk directly along with time stamp reference of when this happens.
                      RayNinjaTrader Customer Service

                      Comment


                        #12
                        OK, I have it for this exact situation since I've been running with TraceOrders on since the first occurrence. Will send to Dierk.

                        Comment


                          #13
                          >> which left it as a sell and not a buy
                          There is no way NT could change an order type from buy to sell. It 's technically just not possible.

                          Comment


                            #14
                            Curious, does any of your custom signals go by:
                            - "Stop loss"
                            - "Profit target"
                            - "Trail stop"

                            I believe this could conflict with internal signal names which NT generates for stop/targets...

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                            0 responses
                            647 views
                            0 likes
                            Last Post Geovanny Suaza  
                            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                            0 responses
                            368 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
                            572 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