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

Cancelled pending exit order, since associated...

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

    Cancelled pending exit order, since associated...

    After running a backtest on a strategy with advanced orders i'm getting a slew of messages at the end of the TraceOrders that read like: 4/21/2009 11:00:45 AM Cancelled pending exit order, since associated position is closed: Order='NT-00002/Back101' Name='exit.0' State=Initialized Instrument='$USDJPY' Action=BuyToCover Limit price=0 Stop price=0 Quantity=1 Strategy='BAMMultiTemplate' Type=Market Tif=Gtc Oco='' Filled=1 Fill price=99.4 Token='59412ec6ba3e411abc6d7e5477d014c4' Gtd='12/1/2099 12:00:00 AM'

    However the exit order has been executed, it seems somewhere another exit order with the same name and a different Token are being created. Any idea what may be causing the problem?
    Attached Files

    #2
    From your output I am reading an "Exit on Close" order being submitted which closes all open positions. This is why any additional stops/targets/etc you may have had now receives the message you are seeing. If you do not wish to use "Exit on Close" please set that property to false in the strategy parameters.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      I have Exit on close set to false. Its only being reported because the backtest has finished the available data and the strategy has an open position and in the begining of OnExecution i have:

      Print("executed: " + execution.Order.ToString());

      The order being cancelled at the end of the run is:
      Order='NT-00002/Back101' Name='exit.0' State=Initialized

      But in line number 11 of the output the same order, but with a different token has already been executed:
      Order='NT-00002/Back101' Name='exit.0' State=Filled

      Only seems to be a problem when the exit orders are placed as more then one market order. The position is being entered with two separate market orders, and closed with two separate market orders. It appears that this message comes at the end for any closing market order that does not flatten the position.

      Say you have:

      entry.0
      entry.1
      entry.2

      and then exit with

      exit.0
      exit.1
      exit.2

      exit.0 and exit.1 will generate Cancelled pending exit order... messages.

      Comment


        #4
        Please post your code used for entries and exits.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Entries:
          Code:
          [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] i = 0; i < entries; i++)
          {
          [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (disposition == 1) entry[i] = EnterLong(bip, increment, [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"entry."[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + i);
          [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (disposition == -1) entry[i] = EnterShort(bip, increment, [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"entry."[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + i);
          Print([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"submitted: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + entry[i].ToString());
          [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]break[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
          }
          [/SIZE]
          Exits:
          Code:
          [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] i = 0; i < entries; i++)
          {
          [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (entry[i] != [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] && (entry[i].OrderState == OrderState.Filled || entry[i].OrderState == OrderState.PartFilled)) 
          { 
          [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (entry[i].Action == Action.Buy) exit[i] = ExitLong(bip,entry[i].Filled,[/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"exit."[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + i,entry[i].Name);
          [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (entry[i].Action == Action.SellShort) exit[i] = ExitShort(bip,entry[i].Filled,[/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"exit."[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + i,entry[i].Name);
          [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (debug) Print([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"submitted: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + exit[i].ToString());
          }
          [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (entry[i] != [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] && entry[i].OrderState == OrderState.Working) 
          {
          [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (debug) Print([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"cancelling: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + entry[i].ToString());
          [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]try[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] {CancelOrder(entry[i]);} [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]catch[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Exception[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] e) { Print(e.ToString()); }
          }
          }
          [/SIZE]
          OnUpdate()

          Code:
          [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (debug) Print([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"executed: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + execution.Order.ToString());
          [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (exit[i] != [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] && exit[i].Token == execution.Order.Token && execution.Order.OrderState == OrderState.Filled)
          {
          [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]try[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] {CancelOrder(entry[i]);} [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]catch[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Exception[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] e) { Print(e.ToString()); }
          entry[i] = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
          [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]try[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] {CancelOrder(exit[i]);} [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]catch[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Exception[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] e) { Print(e.ToString()); }
          exit[i] = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
          }[/SIZE]

          Comment


            #6
            darckeen,

            Unfortunately use of arrays is beyond what we can support. Please simplify your case down and not use arrays. Try again with just a very simple setup where you specifically type out the entry and the exit signal names. Please try with only one market direction at a time too. Thank you.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Okies here is a simplified version and associated TraceOrder output.

              Thanks for your help.
              Attached Files
              Last edited by darckeen; 04-21-2009, 03:22 PM.

              Comment


                #8
                Actually was able pair it down a good bit more. This code will execute one trade and will generate the afore mentioned message at the end of the run. As you can see from the output somehow an exit order is being created internally that is the same as the filled exit1 order except that it has a different token.
                Attached Files
                Last edited by darckeen; 04-22-2009, 04:37 AM.

                Comment


                  #9
                  darckeen,

                  I am investigating your submitted strategy and will get back to you when I determine something.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    darckeen,

                    This message comes up when you switch over to the Chart tab. It is superfluous and has no impact on your strategy. For the time being you can ignore this message. We will apply a fix to remove it. Thank you for bringing this to our attention.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks alot Josh, appreciate your looking into this. If anything trying to figure out why this was happening gave me a much better understanding of how the internal order management system works. What i've found is that a system that uses multiple advanced orders that works live is pretty darn hard to implement lol. Most of the difficulty i've encountered is due to the internal order queing where it seems to square a position when exit orders are submitted in OnBarUpdate then entry orders are submitted in the same OnBarUpdate. What seems to happen is that as soon as an entry order is recieved NT submits an internally generated "Close position" order. This will be processed along with the other exit orders and the position will get out of whack. Is there anyway to disable these internally generated "Close position" orders?

                      Comment


                        #12
                        darckeen,

                        You cannot disable them. The "Close position" orders only occur if you were in a long position and you submitted a enter short order. The vice versa case would apply also. What NT does is reverse your position for you. If you do not want to reverse submit an ExitLong() instead of EnterShort().
                        Josh P.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by trilliantrader, Today, 08:16 AM
                        0 responses
                        3 views
                        0 likes
                        Last Post trilliantrader  
                        Started by AttiM, 02-14-2024, 05:20 PM
                        9 responses
                        174 views
                        0 likes
                        Last Post NinjaTrader_BrandonH  
                        Started by funk10101, Today, 08:14 AM
                        0 responses
                        2 views
                        0 likes
                        Last Post funk10101  
                        Started by adeelshahzad, Today, 03:54 AM
                        1 response
                        13 views
                        0 likes
                        Last Post NinjaTrader_BrandonH  
                        Started by RookieTrader, Today, 07:41 AM
                        1 response
                        5 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Working...
                        X