Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Limit orders not cancelled by next bar

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

    Limit orders not cancelled by next bar

    I have a strategy that uses managed limit orders to enter trades.

    Sometimes, when flat a limit buy will be placed one bar, not get filled, then on the next bar a limit sell will be placed and will be ignored due to order handling rules.

    I can't figure out what rule its violating since the strategy is flat and the limit order that was not filled should have been cancelled since its the next bar.

    Is there any to accomplish what I'd like to do using managed orders?

    This code will reproduce the error for the second trade:

    Code:
    [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]public[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]class[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] TEST2 : Strategy[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Initialize()[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]CalculateOnBarClose = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]TraceOrders = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
     
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] OnBarUpdate()[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (CurrentBar % [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] == [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]EnterLongLimit([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/FONT]
    [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]EnterShortLimit([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2].MaxValue);[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
    [/SIZE][/FONT]
    Here is the TraceOrders output:

    Code:
    1/3/2011 11:15:00 AM Entered internal PlaceOrder() method at 1/3/2011 11:15:00 AM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=100 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
    1/3/2011 11:20:00 AM Entered internal PlaceOrder() method at 1/3/2011 11:20:00 AM: BarsInProgress=0 Action=SellShort OrderType=Limit Quantity=100 LimitPrice=Infinity StopPrice=0 SignalName='' FromEntrySignal=''
    1/3/2011 11:20:00 AM Ignored PlaceOrder() method at 1/3/2011 11:20:00 AM: Action=SellShort OrderType=Limit Quantity=100 LimitPrice=Infinity StopPrice=0 SignalName=Sell short' FromEntrySignal='' Reason='An Enter() method to submit an entry order has been ignored. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation.'
    **NT** An Enter() method to submit an entry order at '1/3/2011 11:20:00 AM' has been ignored. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation.
    1/3/2011 11:20:00 AM Cancelled expired order: BarsInProgress=0: Order='NT-00000/Backtest' Name='Buy' State=Working Instrument='SPY' Action=Buy Limit price=0 Stop price=0 Quantity=100 Strategy='TEST2' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='555b7ccaa03548fa8be98c0032d836d4' Gtd='12/1/2099 12:00:00 AM'
    1/3/2011 11:25:00 AM Entered internal PlaceOrder() method at 1/3/2011 11:25:00 AM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=100 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
    1/3/2011 11:30:00 AM Entered internal PlaceOrder() method at 1/3/2011 11:30:00 AM: BarsInProgress=0 Action=SellShort OrderType=Limit Quantity=100 LimitPrice=Infinity StopPrice=0 SignalName='' FromEntrySignal=''
    1/3/2011 11:30:00 AM Cancelled expired order: BarsInProgress=0: Order='NT-00001/Backtest' Name='Buy' State=Working Instrument='SPY' Action=Buy Limit price=0 Stop price=0 Quantity=100 Strategy='TEST2' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='c410c1ba1de144a3a7c8bfdcab39e6d1' Gtd='12/1/2099 12:00:00 AM'
    1/3/2011 11:35:00 AM Entered internal PlaceOrder() method at 1/3/2011 11:35:00 AM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=100 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
    1/3/2011 11:40:00 AM Entered internal PlaceOrder() method at 1/3/2011 11:40:00 AM: BarsInProgress=0 Action=SellShort OrderType=Limit Quantity=100 LimitPrice=Infinity StopPrice=0 SignalName='' FromEntrySignal=''
    1/3/2011 11:40:00 AM Cancelled expired order: BarsInProgress=0: Order='NT-00002/Backtest' Name='Buy' State=Working Instrument='SPY' Action=Buy Limit price=0 Stop price=0 Quantity=100 Strategy='TEST2' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='eb83fbc84aae4dcab5597309d3774261' Gtd='12/1/2099 12:00:00 AM'
    1/3/2011 11:45:00 AM Entered internal PlaceOrder() method at 1/3/2011 11:45:00 AM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=100 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
    1/3/2011 11:50:00 AM Entered internal PlaceOrder() method at 1/3/2011 11:50:00 AM: BarsInProgress=0 Action=SellShort OrderType=Limit Quantity=100 LimitPrice=Infinity StopPrice=0 SignalName='' FromEntrySignal=''
    1/3/2011 11:50:00 AM Cancelled expired order: BarsInProgress=0: Order='NT-00003/Backtest' Name='Buy' State=Working Instrument='SPY' Action=Buy Limit price=0 Stop price=0 Quantity=100 Strategy='TEST2' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='5b0d1604fcac488089659be56cdca8dd' Gtd='12/1/2099 12:00:00 AM'
    1/3/2011 11:55:00 AM Entered internal PlaceOrder() method at 1/3/2011 11:55:00 AM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=100 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
    1/3/2011 12:00:00 PM Entered internal PlaceOrder() method at 1/3/2011 12:00:00 PM: BarsInProgress=0 Action=SellShort OrderType=Limit Quantity=100 LimitPrice=Infinity StopPrice=0 SignalName='' FromEntrySignal=''
    1/3/2011 12:00:00 PM Cancelled expired order: BarsInProgress=0: Order='NT-00004/Backtest' Name='Buy' State=Working Instrument='SPY' Action=Buy Limit price=0 Stop price=0 Quantity=100 Strategy='TEST2' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='df5c5a47a6594110bf59812e747a492f' Gtd='12/1/2099 12:00:00 AM'
    1/3/2011 12:05:00 PM Entered internal PlaceOrder() method at 1/3/2011 12:05:00 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=100 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
    1/3/2011 12:10:00 PM Entered internal PlaceOrder() method at 1/3/2011 12:10:00 PM: BarsInProgress=0 Action=SellShort OrderType=Limit Quantity=100 LimitPrice=Infinity StopPrice=0 SignalName='' FromEntrySignal=''

    #2
    darckeen, it looks like you would need to introduce another sequencing here, as the order is placed before the expiration of your other orders takes place, thus running into the rules.

    Comment


      #3
      I see. Is there anyway to stop the error messages from printing to the output window and the log?

      Comment


        #4
        You could just run without TraceOrders in your Initialize().

        Comment


          #5
          Is there any way to avoid having:

          **NT** An Enter() method to submit an entry order at '1/3/2011 11:20:00 AM' has been ignored. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation.

          written to the output window and logs?

          Comment


            #6
            Unfortunately those would still show darckeen.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            655 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            370 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            109 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            574 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            577 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X