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

Unmanaged orders: multi orders with the same OrderAction

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

    Unmanaged orders: multi orders with the same OrderAction

    Hi,

    I have an unmanaged stock strategy.

    When I use strategy analyzer to simulate the strategy all OK.
    The problem is when I use playback on historical data.

    I subit these orders:

    SubmitOrderUnmanaged(0,OrderAction.SellShort, OrderType.Limit, quantity, limitPrice, 0, oco, "Example1");
    SubmitOrderUnmanaged(0,OrderAction.BuyToCover, OrderType.StopMarket, quantity, 0, stopLossPrice, oco, "Example2");
    SubmitOrderUnmanaged(0,OrderAction.BuyToCover, OrderType.Limit, quantity1, targetPrice1, 0, "Target1", "Example3");
    SubmitOrderUnmanaged(0,OrderAction.BuyToCover, OrderType.Limit, quantity2, targetPrice2, 0, "Target2", "Example4");

    The first two orders are executed correctly, the other two remain initialized orders.

    Trying I realized that the problem is that OrderAction is the same for the last three orders (all BuyToCover)

    Some solution?

    Thanks Alberto
    Last edited by Apo84; 01-12-2022, 08:14 AM.

    #2
    Hello Apo84,

    Thank you for your reply.

    Looks like this is likely occurring because you're using "Target1" and "Target2" where it's expecting that parameter to be the oco value. Does changing these to the following allow them to move beyond initialized?

    SubmitOrderUnmanaged(0,OrderAction.BuyToCover, OrderType.Limit, quantity1, targetPrice1, 0, "", "Target1");
    SubmitOrderUnmanaged(0,OrderAction.BuyToCover, OrderType.Limit, quantity2, targetPrice2, 0, "", "Target2");

    If you're trying to link entries and exits with Signal Names that won't work with the unmanaged approach - that's only with Managed that signal names come into play.

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Thanks for answer.

      I tried:

      SubmitOrderUnmanaged(0,OrderAction.SellShort, OrderType.Limit, quantity, limitPrice, 0, "", "Example1");
      SubmitOrderUnmanaged(0,OrderAction.BuyToCover, OrderType.StopMarket, quantity, 0, stopLossPrice, "", "Example2");
      SubmitOrderUnmanaged(0,OrderAction.BuyToCover, OrderType.Limit, quantity1, targetPrice1, 0, "", "Example3");

      the first two orders work, the last one does not enter and trying to change ActionOrder, all three go.
      But I need OrderAction.BuyToCover.

      Comment


        #4
        No, it does not work.

        the first two orders work and the third does not, whatever changes I make.

        I don't know.

        PS: log file
        Failed to submit orders: System.NullReferenceException: Object reference not set to an instance of an object. at NinjaTrader.Cbi.Account.UpdateAccountItems(DateTim e now, Boolean force) at NinjaTrader.Cbi.Account.Submit(IEnumerable`1 orders)

        Comment


          #5
          Hello Apo84,

          Thank you for your reply.

          I've created a simple example strategy that submits multiple targets for a short position with the same stop level in an unmanaged script that may be helpful. Note how we don't submit the targets and stops until the entry fills in OnOrderUpdate.

          Please let us know if we may be of further assistance to you.
          Attached Files
          Kate W.NinjaTrader Customer Service

          Comment


            #6
            Thanks for the answer and for the example.

            I tried to use your example and it gives me the same problem.
            I understand that the problem is related to the function: SubmitOrderUnmanaged, no orders are created!
            Basically, the sell order is filled, only the first order between stopLoss and target is executed.
            The problem is not there if I use strategy analyzer, there is when I use playback (on historical data) or in real-time.

            Thanks

            Comment


              #7
              Hello Apo84,

              Thank you for your reply.

              Looks like that example had some issues with partial fills stemming from using a single entry order instead of 2 separate entries. I've attached a better example below.

              I am seeing this take trades using playback and on live as I would expect, using a separate entry for each set of stops and targets.

              Please let us know if we may be of further assistance to you.
              Attached Files
              Kate W.NinjaTrader Customer Service

              Comment


                #8
                Hi,
                Thanks for the answer and for the example.

                The problem is the some. Orders remain initialized orders.
                is it a data problem? I got them from kinetick.

                Thanks
                Attached Files

                Comment


                  #9
                  Hello Apo84,

                  I tested the strategy Kate had posted from post #7, and I cannot reproduce those symptoms.

                  I tested a clean environment of Release 25 on Kinetick data and on Playback. Below is a video of my tests:



                  Could you set up a clean environment and advise me on any steps I need to take to reproduce the symptom with the test strategy? Video and/or written steps can help.

                  Note, that I added if (State == State.Historical) return; so we would submit orders as soon as we are processing realtime data.

                  Clean Environment Test:

                  Creating a clean environment can be done by following the steps below:
                  1. Close NinjaTrader 8, and rename the "NinjaTrader 8" folder in My Documents to something like: "NinjaTrader 8 OLD" Do not delete this folder.
                  2. Uninstall NinjaTrader from the Windows Control Panel
                  3. Delete the C:\Program Files (x86)\NinjaTrader 8 folder
                  4. Reinstall using the installer from http://ninjatrader.com/PlatformDirect
                  5. Import the test script from post #7 (optional: add the line of code to skip processing historical data)
                  6. Test to reproduce the stuck Initialize symptom
                  If you ever need to switch back to your original platform, you may do so by closing NinjaTrader and swapping the platform folder names.

                  For example, Close NinjaTrader and rename the new "NinjaTrader 8" folder to "NinjaTrader 8 NEW" and the "NinjaTrader 8 OLD" folder to "NinjaTrader 8." Then restart the platform. Simply put: NinjaTrader 8 will always load the "NinjaTrader 8" folder in My Documents.
                  JimNinjaTrader Customer Service

                  Comment


                    #10
                    Hi,

                    thanks for the answer.

                    I shut down and restarted NT and everything was fine.
                    I can't understand what happened, could it be some setting related to the simulation account that resets on reboot?

                    Thanks Alberto

                    Comment


                      #11
                      Hello Apo84,

                      It is possible.

                      If you were developing something, there is a chance some actions taken while developing/testing affected the simulator where it then started giving you orders stuck in Initialized.
                      JimNinjaTrader Customer Service

                      Comment


                        #12
                        Hi,

                        thanks for the answer.

                        I found that it happens when I change Risk Account without rebooting NT.
                        Thanks

                        Comment


                          #13
                          Hello Apo84,

                          I would like to report this, but I haven't been able to reproduce.

                          Could you give some explicit steps to set up?

                          Screenshots or a video can be helpful.
                          JimNinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Option Whisperer, Today, 09:55 AM
                          1 response
                          11 views
                          0 likes
                          Last Post bltdavid  
                          Started by port119, Today, 02:43 PM
                          0 responses
                          1 view
                          0 likes
                          Last Post port119
                          by port119
                           
                          Started by Philippe56140, Today, 02:35 PM
                          0 responses
                          3 views
                          0 likes
                          Last Post Philippe56140  
                          Started by 00nevest, Today, 02:27 PM
                          0 responses
                          2 views
                          0 likes
                          Last Post 00nevest  
                          Started by Jonafare, 12-06-2012, 03:48 PM
                          5 responses
                          3,986 views
                          0 likes
                          Last Post rene69851  
                          Working...
                          X