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

Managed vs. UnManaged Trades

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

    Managed vs. UnManaged Trades

    Hi -

    I am testing a new order management system using NT's simple MA strategy and I'm running into the "An Enter() method to submit an entry order....has been ignored" error. I can reproduce this issue. So, there's something systemic about how trade orders are being handled.

    First, here's the problem:
    (i) Sometimes ALL the Trade Set's orders get submitted and accepted OR (ii) ONLY the market order per trade set gets submitted and the limit orders don't get submitted for the trade set. A trade set contains 1x market order & 5 x limit orders invoked at the time of signal.

    - Timeframe: 3M, single timeframe
    - Asset: ES
    - Strategy: long and short
    - # Trades: 8 trades max per direction
    - Exit on session close

    My system trades in trade sets. A trade set contains 1 x market order and 5 x limit orders. The same for both longs and shorts.

    So, a long trade set uses the following Enter() methods:

    (1) entryOrder_1 = EnterLong(quantity_1, order_1);
    (2) entryOrder_2 = EnterLongLimit(0, true, quantity_2, order_2);
    ...
    (6) entryOrder_6 = EnterLongLimit(0, true, quantity_6, order_6);

    I've simplified the above but that captures the gist.

    (7) OnOrderUpdate(...) I save the Order object for future reference for each trade order for the trade set using the name of the order to then save the results in a Dictionary object.

    The problem appears to manifest itself after the first trade set.

    (a) The first trade for the 2 week timeframe I'm testing is short. So, 6 short trade orders are submitted and I can see all 6 trade orders when I trace order.ToString() OnOrderUpdate().
    (b) Some short orders get filled, some are "waiting" for the right "limit" price to get filled. So far, so good.
    (c) Long signal gets triggered
    (d) All 6 x short orders get submitted for cancelation
    (e) 1st long market order gets submitted -- and awaits the shorts to get closed
    (f) NONE of the other 5 x long limit orders get submitted -- error message
    (g) Error message: "An Enter() method to..."
    (h) All short positions and pending orders get closed or canceled
    (i) Long market order gets filled. None of the other long limit orders get submitted or filled.
    (j) Strategy continues to move forward
    (k) etc....


    So...Sometimes ALL the Trade Set's orders get submitted and accepted OR (ii) ONLY the market order per trade set gets submitted and filled and the limit orders don't get submitted.


    Thanks,

    Big Surf
    Last edited by bigsurftrader; 03-15-2017, 11:00 AM.

    #2
    Selfishly bumping this ;-)

    Hoping NT can provide some clarity into issue of sequential market and limit orders that I am seeing.

    Comment


      #3
      Hello bigsurftrader,

      Thank you for your note.

      You would not be able to submit both enter long limit and enter short limit orders at the same time due to Internal Order Handling Rules. You can view the Internal Order Handling Rules at the following link:



      If you wish to work with Unmanaged Orders you may do so and the orders would not be ignored in this case.

      Please let us know if you need further assistance.
      Alan P.NinjaTrader Customer Service

      Comment


        #4
        Hi Alan -

        To clarify -- I only trade in one direction at a time. So, there won't be an instance of EnterLong and EnterShort being made on the same bar.

        Comment


          #5
          What i'm referring to is:
          1x Market enter long
          5 x Limit enter long

          ...a few bars or hours later...

          Close long trades
          1x Market enter short
          5x Limit enter short

          Comment


            #6
            If you can, please thoroughly read through the scenario I posted in the 1st post. It explains in detail how I'm able to replicate this issue.

            Comment


              #7
              Here's a code example to reproduce the error using the NT "SampleMACrossOver":

              if (CrossAbove(SmaFast, SmaSlow, 1)){

              EnterLong(quantity, "Long_"+CurrentBar+"1");
              EnterLongLimit(0,true, quantity, GetCurrentBid()-.5,"Long_"+CurrentBar+"_2");
              EnterLongLimit(0,true, quantity, GetCurrentBid()-1,"Long_"+CurrentBar+"_3");
              EnterLongLimit(0,true, quantity, GetCurrentBid()-1.25,"Long_"+CurrentBar+"_4");
              EnterLongLimit(0,true, quantity, GetCurrentBid()-1.75,"Long_"+CurrentBar+"_5");

              }
              else if (CrossBelow(SmaFast, SmaSlow, 1)){
              EnterShort(quantity, "Short_"+CurrentBar+"1");
              EnterShortLimit(0,true, quantity, GetCurrentBid()+.5,"Short_"+CurrentBar+"_2");
              EnterShortLimit(0,true, quantity, GetCurrentBid()+1,"Short_"+CurrentBar+"_3");
              EnterShortLimit(0,true, quantity, GetCurrentBid()+1.25,"Short_"+CurrentBar+"_4");
              EnterShortLimit(0,true, quantity, GetCurrentBid()+1.75,"Short_"+CurrentBar+"_5");
              }

              To reproduce the error here are the Strategy Analyzer settings:

              I've attached an image.

              Comment


                #8
                Here's the code with some order output-logging that clearly illustrates the problem I'm seeing.

                Code below:

                Order long1;
                Order long2;
                Order long3;
                Order long4;
                Order long5;

                Order short1;
                Order short2;
                Order short3;
                Order short4;
                Order short5;
                protected override void OnBarUpdate()
                {
                if (CurrentBar < BarsRequiredToTrade)
                return;

                int quantity = 3;

                if (CrossAbove(SmaFast, SmaSlow, 1)){

                CancelOrder(short1);
                CancelOrder(short2);
                CancelOrder(short3);
                CancelOrder(short4);
                CancelOrder(short5);

                EnterLong(quantity, "Long_"+CurrentBar+"_1_");
                EnterLongLimit(0,true, quantity, GetCurrentBid()-.5,"Long_"+CurrentBar+"_2_");
                EnterLongLimit(0,true, quantity, GetCurrentBid()-1,"Long_"+CurrentBar+"_3_");
                EnterLongLimit(0,true, quantity, GetCurrentBid()-1.25,"Long_"+CurrentBar+"_4_");
                EnterLongLimit(0,true, quantity, GetCurrentBid()-1.75,"Long_"+CurrentBar+"_5_");

                }
                else if (CrossBelow(SmaFast, SmaSlow, 1)){

                CancelOrder(long1);
                CancelOrder(long2);
                CancelOrder(long3);
                CancelOrder(long4);
                CancelOrder(long5);

                EnterShort(quantity, "Short_"+CurrentBar+"_1_");
                EnterShortLimit(0,true, quantity, GetCurrentBid()+.5,"Short_"+CurrentBar+"_2_");
                EnterShortLimit(0,true, quantity, GetCurrentBid()+1,"Short_"+CurrentBar+"_3_");
                EnterShortLimit(0,true, quantity, GetCurrentBid()+1.25,"Short_"+CurrentBar+"_4_");
                EnterShortLimit(0,true, quantity, GetCurrentBid()+1.75,"Short_"+CurrentBar+"_5_");
                }
                }

                protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
                {

                // if entry order exists
                if (order != null)
                {
                // Order Submitted and Accepted by broker, update the Order object
                if (orderState == OrderState.Accepted && (order.OrderAction == OrderAction.Buy)){

                if (order.Name.Contains("_1_")){
                long1 = order;
                Print("long order 1 assigned");
                }
                else if (order.Name.Contains("_2_")){
                long2 = order;
                Print("long order 2 assigned");
                }
                else if (order.Name.Contains("_3_")){
                long3 = order;
                Print("long order 3 assigned");
                }
                else if (order.Name.Contains("_4_")){
                long4 = order;
                Print("long order 4 assigned");
                }
                else if (order.Name.Contains("_5_")){
                long5 = order;
                Print("long order 5 assigned");
                }
                }

                if (orderState == OrderState.Accepted && (order.OrderAction == OrderAction.SellShort)){

                if (order.Name.Contains("_1_"))
                short1 = order;
                else if (order.Name.Contains("_2_"))
                short2 = order;
                else if (order.Name.Contains("_3_"))
                short3 = order;
                else if (order.Name.Contains("_4_"))
                short4 = order;
                else if (order.Name.Contains("_5_"))
                short5 = order;

                }
                }
                }

                Comment


                  #9
                  Hello bigsurftrader,

                  Under the following link, see Internal Order Handling Rules that Reduce Unwanted Positions.


                  I have attached a sample strategy which I suggest you apply to a 5 second chart and enable chart trader so you can see the limit orders working. The strategy opens a position using a market long order and submits long limit orders below the market. After 3 bars pass, an entershort method is called along with EnterShortLimit call, the latter is ignored and logs the following message,

                  Strategy 'MyCustomStrategy6/100895805': An Enter() method to submit an entry order at '3/16/2017 8:57:05 AM' has been ignored. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation.
                  This is expected and explained in the link above. To do what you’re trying to do you should use the unmanaged order method,


                  Please let us know if you need further assistance.
                  Attached Files
                  Alan P.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks Alan. I'll take a look...

                    Comment


                      #11
                      Alan - I've read the managed and unmanaged documentation through multiple times. So It's probably not clear to me which portion of the "managed" rules I'm violating. Could you help explain to me or highlight the area/sentences?

                      Thanks!

                      Comment


                        #12
                        Thanks for all your help Alan. No need to reply to this post and my questions.

                        I'm converting my code to the Unmanaged approach 100% and I actually prefer this method over the Managed approach because of the transparency/control of the trade orders and positions.

                        Thank you once again!!

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Perr0Grande, Today, 08:16 PM
                        0 responses
                        2 views
                        0 likes
                        Last Post Perr0Grande  
                        Started by elderan, Today, 08:03 PM
                        0 responses
                        5 views
                        0 likes
                        Last Post elderan
                        by elderan
                         
                        Started by algospoke, Today, 06:40 PM
                        0 responses
                        10 views
                        0 likes
                        Last Post algospoke  
                        Started by maybeimnotrader, Today, 05:46 PM
                        0 responses
                        12 views
                        0 likes
                        Last Post maybeimnotrader  
                        Started by quantismo, Today, 05:13 PM
                        0 responses
                        7 views
                        0 likes
                        Last Post quantismo  
                        Working...
                        X