Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi instrument order glitch/bug/question?

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

    Multi instrument order glitch/bug/question?

    I've been trying to work through a problem I'm getting with strategies that use many instruments and also use the advanced ordering methods.

    I whipped up a strategy which enters a market position on the 5th bar of each session, then in the OnOrderUpdate, when the order is filled, it places a stop and a target. (I know about SetProfitTarget, but I want to use partials and I keep getting glitches so I'm doing it manually. I also don't want to use 3-4 separate entries with separate targets & stops because the commission and slippage for fragmented orders will eat me alive.)

    Anyway, when I take an order with BarsInProgress==0, then everything works well. I enter the position and either get stopped out or I hit my target, life is good.

    BUT, when I take an order with BarsInProgress==1, then my stop and limit orders get rejected. The message in the OutputWindow is that I don't have a position, yet before sending the order, I explicitly check (Position.MarketPosition != MarketPosition.Flat).


    I can't figure out what's going on. It looks like this is a bug and the position is not being updated correctly for multi-instrument strategies. (I was noticing similar glitches with placing advanced orders.)

    To show you what I'm doing, I'm attaching 'TimeframeDemoStrategy'.

    I run it with AAPL using 1min data from Apr 17 - 24th, BarsRequired = 0. The strategy will load BIDU for the same period and take four trades, all of which will get stopped out at the end of day.

    Then change the Add() line to be "AAPL" and the "BarsInProgress == 0" and run the strategy against BIDU. We've just switched the instruments from position 0 to 1 and vice versa, so the results should be identical. Instead, when BIDU is in position 0, the strategy hits its stop orders and profit targets!
    Attached Files

    #2
    Josh will follow up later today.
    RayNinjaTrader Customer Service

    Comment


      #3
      When I run with orders triggering from BarsInProgress == 0, this is what I get for TraceOrders:

      Code:
      4/16/2008 6:36:00 AM Entered internal PlaceOrder() method at 4/16/2008 6:36:00 AM: Action=Buy OrderType=Market Quantity=100 LimitPrice=0 StopPrice=0 SignalName='L BIDU' FromEntrySignal=''
      4/16/2008 6:36:00 AM Entered internal PlaceOrder() method at 4/16/2008 6:36:00 AM: Action=Sell OrderType=Stop Quantity=100 LimitPrice=0 StopPrice=291.91 SignalName='Stp BIDU' FromEntrySignal='L BIDU'
      4/16/2008 6:36:00 AM Entered internal PlaceOrder() method at 4/16/2008 6:36:00 AM: Action=Sell OrderType=Limit Quantity=100 LimitPrice=293.59 StopPrice=0 SignalName='Tgt BIDU' FromEntrySignal='L BIDU'
      4/16/2008 6:36:00 AM Cancelled pending exit order, since associated position is closed: Order='NT-00002/Back101' Name='Tgt BIDU' State=Working Instrument='BIDU' Action=Sell Limit price=293.59 Stop price=0 Quantity=100 Strategy='TimeframeDemoStrategy' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='7d9c3bc17f5c4e89a41f25d9ed8b4020' Gtd='12/1/2099 12:00:00 AM'
      4/17/2008 6:36:00 AM Entered internal PlaceOrder() method at 4/17/2008 6:36:00 AM: Action=Buy OrderType=Market Quantity=100 LimitPrice=0 StopPrice=0 SignalName='L BIDU' FromEntrySignal=''
      4/17/2008 6:36:00 AM Entered internal PlaceOrder() method at 4/17/2008 6:36:00 AM: Action=Sell OrderType=Stop Quantity=100 LimitPrice=0 StopPrice=319.57 SignalName='Stp BIDU' FromEntrySignal='L BIDU'
      4/17/2008 6:36:00 AM Entered internal PlaceOrder() method at 4/17/2008 6:36:00 AM: Action=Sell OrderType=Limit Quantity=100 LimitPrice=322.65 StopPrice=0 SignalName='Tgt BIDU' FromEntrySignal='L BIDU'
      4/17/2008 6:36:00 AM Cancelled pending exit order, since associated position is closed: Order='NT-00005/Back101' Name='Tgt BIDU' State=Working Instrument='BIDU' Action=Sell Limit price=322.65 Stop price=0 Quantity=100 Strategy='TimeframeDemoStrategy' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='ddd39ced94094dd89ca3816c5ead029a' Gtd='12/1/2099 12:00:00 AM'
      4/18/2008 6:36:00 AM Entered internal PlaceOrder() method at 4/18/2008 6:36:00 AM: Action=Buy OrderType=Market Quantity=100 LimitPrice=0 StopPrice=0 SignalName='L BIDU' FromEntrySignal=''
      4/18/2008 6:36:00 AM Entered internal PlaceOrder() method at 4/18/2008 6:36:00 AM: Action=Sell OrderType=Stop Quantity=100 LimitPrice=0 StopPrice=333.48 SignalName='Stp BIDU' FromEntrySignal='L BIDU'
      4/18/2008 6:36:00 AM Entered internal PlaceOrder() method at 4/18/2008 6:36:00 AM: Action=Sell OrderType=Limit Quantity=100 LimitPrice=337.45 StopPrice=0 SignalName='Tgt BIDU' FromEntrySignal='L BIDU'
      4/18/2008 6:36:00 AM Cancelled pending exit order, since associated position is closed: Order='NT-00008/Back101' Name='Tgt BIDU' State=Working Instrument='BIDU' Action=Sell Limit price=337.45 Stop price=0 Quantity=100 Strategy='TimeframeDemoStrategy' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='253a0bf1b7d34fd5a2d964f8f2c44cad' Gtd='12/1/2099 12:00:00 AM'
      4/21/2008 6:36:00 AM Entered internal PlaceOrder() method at 4/21/2008 6:36:00 AM: Action=Buy OrderType=Market Quantity=100 LimitPrice=0 StopPrice=0 SignalName='L BIDU' FromEntrySignal=''
      4/21/2008 6:36:00 AM Entered internal PlaceOrder() method at 4/21/2008 6:36:00 AM: Action=Sell OrderType=Stop Quantity=100 LimitPrice=0 StopPrice=340.26 SignalName='Stp BIDU' FromEntrySignal='L BIDU'
      4/21/2008 6:36:00 AM Entered internal PlaceOrder() method at 4/21/2008 6:36:00 AM: Action=Sell OrderType=Limit Quantity=100 LimitPrice=342.65 StopPrice=0 SignalName='Tgt BIDU' FromEntrySignal='L BIDU'
      4/21/2008 6:36:00 AM Cancelled pending exit order, since associated position is closed: Order='NT-00010/Back101' Name='Stp BIDU' State=Working Instrument='BIDU' Action=Sell Limit price=0 Stop price=340.26 Quantity=100 Strategy='TimeframeDemoStrategy' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='e6ac07973ca743aab158c396aec7a601' Gtd='12/1/2099 12:00:00 AM'


      When I run with BarsInProgress == 1, this is what I get. Notice how all of my limit and stop orders get ignored:
      Code:
      4/16/2008 6:36:00 AM Entered internal PlaceOrder() method at 4/16/2008 6:36:00 AM: Action=Buy OrderType=Market Quantity=100 LimitPrice=0 StopPrice=0 SignalName='L BIDU' FromEntrySignal=''
      4/16/2008 6:36:00 AM Entered internal PlaceOrder() method at 4/16/2008 6:36:00 AM: Action=Sell OrderType=Stop Quantity=100 LimitPrice=0 StopPrice=291.91 SignalName='Stp BIDU' FromEntrySignal='L BIDU'
      4/16/2008 6:36:00 AM Ignored PlaceOrder() method: Action=Sell OrderType=Stop Quantity=100 LimitPrice=0 StopPrice=291.91 SignalName='Stp BIDU' FromEntrySignal='L BIDU' Reason='This was an exit order but no position exists to exit'
      4/16/2008 6:36:00 AM Entered internal PlaceOrder() method at 4/16/2008 6:36:00 AM: Action=Sell OrderType=Limit Quantity=100 LimitPrice=293.59 StopPrice=0 SignalName='Tgt BIDU' FromEntrySignal='L BIDU'
      4/16/2008 6:36:00 AM Ignored PlaceOrder() method: Action=Sell OrderType=Limit Quantity=100 LimitPrice=293.59 StopPrice=0 SignalName='Tgt BIDU' FromEntrySignal='L BIDU' Reason='This was an exit order but no position exists to exit'
      4/17/2008 6:36:00 AM Entered internal PlaceOrder() method at 4/17/2008 6:36:00 AM: Action=Buy OrderType=Market Quantity=100 LimitPrice=0 StopPrice=0 SignalName='L BIDU' FromEntrySignal=''
      4/17/2008 6:36:00 AM Entered internal PlaceOrder() method at 4/17/2008 6:36:00 AM: Action=Sell OrderType=Stop Quantity=100 LimitPrice=0 StopPrice=319.57 SignalName='Stp BIDU' FromEntrySignal='L BIDU'
      4/17/2008 6:36:00 AM Ignored PlaceOrder() method: Action=Sell OrderType=Stop Quantity=100 LimitPrice=0 StopPrice=319.57 SignalName='Stp BIDU' FromEntrySignal='L BIDU' Reason='This was an exit order but no position exists to exit'
      4/17/2008 6:36:00 AM Entered internal PlaceOrder() method at 4/17/2008 6:36:00 AM: Action=Sell OrderType=Limit Quantity=100 LimitPrice=322.65 StopPrice=0 SignalName='Tgt BIDU' FromEntrySignal='L BIDU'
      4/17/2008 6:36:00 AM Ignored PlaceOrder() method: Action=Sell OrderType=Limit Quantity=100 LimitPrice=322.65 StopPrice=0 SignalName='Tgt BIDU' FromEntrySignal='L BIDU' Reason='This was an exit order but no position exists to exit'
      4/18/2008 6:36:00 AM Entered internal PlaceOrder() method at 4/18/2008 6:36:00 AM: Action=Buy OrderType=Market Quantity=100 LimitPrice=0 StopPrice=0 SignalName='L BIDU' FromEntrySignal=''
      4/18/2008 6:36:00 AM Entered internal PlaceOrder() method at 4/18/2008 6:36:00 AM: Action=Sell OrderType=Stop Quantity=100 LimitPrice=0 StopPrice=333.48 SignalName='Stp BIDU' FromEntrySignal='L BIDU'
      4/18/2008 6:36:00 AM Ignored PlaceOrder() method: Action=Sell OrderType=Stop Quantity=100 LimitPrice=0 StopPrice=333.48 SignalName='Stp BIDU' FromEntrySignal='L BIDU' Reason='This was an exit order but no position exists to exit'
      4/18/2008 6:36:00 AM Entered internal PlaceOrder() method at 4/18/2008 6:36:00 AM: Action=Sell OrderType=Limit Quantity=100 LimitPrice=337.45 StopPrice=0 SignalName='Tgt BIDU' FromEntrySignal='L BIDU'
      4/18/2008 6:36:00 AM Ignored PlaceOrder() method: Action=Sell OrderType=Limit Quantity=100 LimitPrice=337.45 StopPrice=0 SignalName='Tgt BIDU' FromEntrySignal='L BIDU' Reason='This was an exit order but no position exists to exit'
      4/21/2008 6:36:00 AM Entered internal PlaceOrder() method at 4/21/2008 6:36:00 AM: Action=Buy OrderType=Market Quantity=100 LimitPrice=0 StopPrice=0 SignalName='L BIDU' FromEntrySignal=''
      4/21/2008 6:36:00 AM Entered internal PlaceOrder() method at 4/21/2008 6:36:00 AM: Action=Sell OrderType=Stop Quantity=100 LimitPrice=0 StopPrice=340.26 SignalName='Stp BIDU' FromEntrySignal='L BIDU'
      4/21/2008 6:36:00 AM Ignored PlaceOrder() method: Action=Sell OrderType=Stop Quantity=100 LimitPrice=0 StopPrice=340.26 SignalName='Stp BIDU' FromEntrySignal='L BIDU' Reason='This was an exit order but no position exists to exit'
      4/21/2008 6:36:00 AM Entered internal PlaceOrder() method at 4/21/2008 6:36:00 AM: Action=Sell OrderType=Limit Quantity=100 LimitPrice=342.65 StopPrice=0 SignalName='Tgt BIDU' FromEntrySignal='L BIDU'
      4/21/2008 6:36:00 AM Ignored PlaceOrder() method: Action=Sell OrderType=Limit Quantity=100 LimitPrice=342.65 StopPrice=0 SignalName='Tgt BIDU' FromEntrySignal='L BIDU' Reason='This was an exit order but no position exists to exit'

      Comment


        #4
        thanks Ray & Josh. Let me know if I can give you any more information.

        Comment


          #5
          Hi adrian,

          I think I know what is going on here. When you use the normal override method for EnterLong() it will automatically submit the order to whichever bar object you are in from the BarsInProgress context.

          Now when you go to the OnOrderUpdate() section your stop/target orders are set to submit to BarsInProgress 0. This is the cause of your troubles. Your entry order is placed on your secondary bars but your stop/targets are being placed to your primary. When it looks at the primary bars and tries to have those exit orders it gets ignored because you don't have an open position on your primary instrument. You need to change the BarsInProgress to 1 for those orders. So change your code to this:

          Code:
          exitStop = ExitLongStop([SIZE=3][COLOR=Red]1[/COLOR][/SIZE], true, entryOrder.Quantity, Low[0]-0.10, 
                                  "Stp " + Instrument.FullName,
                                  "L " + Instrument.FullName);
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by Josh View Post
            Hi adrian,

            I think I know what is going on here. When you use the normal override method for EnterLong() it will automatically submit the order to whichever bar object you are in from the BarsInProgress context.
            Gaaaaahhh

            I read that bit of the help doc so many times, and I just kept seeing it as the bar index, not the BarsInProgress. Stupid, stupid, stupid. Oh man, you're a life saver, thank you Josh, I'm so glad it's something simple even if means I've been a complete dolt.

            Thanks again, you're a huge help!

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            666 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            377 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            110 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            575 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            580 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X