Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    BertrandNinjaTrader Customer Service

    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().
        BertrandNinjaTrader Customer Service

        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.
            BertrandNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by DJ888, 04-16-2024, 06:09 PM
            6 responses
            18 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            1 view
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            6 views
            0 likes
            Last Post Javierw.ok  
            Started by timmbbo, Today, 08:59 AM
            2 responses
            10 views
            0 likes
            Last Post bltdavid  
            Started by alifarahani, Today, 09:40 AM
            6 responses
            41 views
            0 likes
            Last Post alifarahani  
            Working...
            X