• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.


No announcement yet.

Partner 728x90


SubmitOrderUnmanaged Orders Ignored in Real-time Paper Trading

  • Filter
  • Time
  • Show
Clear All
new posts

    SubmitOrderUnmanaged Orders Ignored in Real-time Paper Trading

    I have a strategy that works perfectly in historical simulation. Orders execute properly, but when I run the identical code in paper trading, no orders are ever placed. Strategies NOT using unmanaged orders work properly in paper trading. When using unmanaged orders, I set IsUnmanaged = true; in the State.SetDefaults as the documentation specifies.

    To debug the issue, I enabled TraceOrders = true; in the State.SetDefaults section, but no error messages show in the NJ global log or NinjaScript Output windows. I know the code is running because I can see my Print() statements indicating entry attempts at price X, etc. However no orders are ever submitted.

    You'll see my code here that enters at an offset of the last closing price from data set [1].
    orderEntryLimit = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Limit, 1, Closes[1][0]-EnterLimitOffset*0.25, 0, "", "EntryLimitOrder");
    If someone could explain to me why none of my orders execute in paper trading if I code them as unmanged, that would be great. I am using a NinjaTrader demo account.

    Welcome to the forums studio3d!

    Without the full context of the code, I am only left to speculate at what the issue may be. Taking a guess, the strategy may be restricting order submissions based on the BarsRequiredToTrade property or the strategy may be using WaitUntilFlat and is in a virtual position that needs to be closed before new orders are allowed to be submitted. There may also be an issue with the strategy's behavior for realtime processing. The Playback Connection can be used while testing and debugging to focus on realtime processing.

    Start behaviors can be referenced here - https://ninjatrader.com/support/help..._positions.htm

    Playback connection - https://ninjatrader.com/support/help...connection.htm

    I have tested on my end just now and I have not had an issue using an UnmanagedTemplate strategy and a NinjaTrader Continuum demo account. I have attached this strategy so you may perform the same test on your end. You may also use this template for any debugging and personal development.

    Demo: https://www.screencast.com/t/7XeYxdPAlWex

    Please let me know if there is anything else we can do to assist.
    Attached Files
    JimNinjaTrader Customer Service


      Originally posted by NinjaTrader_Jim View Post
      I have tested on my end just now and I have not had an issue using an UnmanagedTemplate strategy and a NinjaTrader Continuum demo account.
      Hello NinjaTrader_Jim

      I have used your script as a template to develop a complete strategy, sincerely it has been of great and great help. But I have found a bug, in the quantity part of SubmitOrderUnmanaged I have changed quantity by a variable to assign from the interface of the script the amount of contracts desired.
      In very high volatility events, when the number of contracts is higher than 1, stop and profit orders are not logically managed, being able to have more stop orders than profit and on the contrary, even being in the market when it should be flat .
      I have not modified the structure of the script, I have added external modifications that should not affect the operation of the script.
      I remind you that this happens only in events of very high volatility, in simulation it works well.
      for now the solution I do is not very orthodox and I loading the script with the same number of contracts I want.
      Do you have any ideas about it?
      I have reviewed the documentation of the order filling and the partial filling of orders without finding a solution.
      I also thank you for the contribution of the script UnmanagedTemplate_NT8 09-17


        Hello franki,

        I'm glad you have made use of the template.

        The purpose of the strategy is to provide a working example and point out how an Unmanaged strategy can be written. It doesn't necessarily provide a working example for all concepts and things you might run into when deployed live. The partial fill handling could be improved for example, but at this time the script was not written to encounter partial fills and merely points you in the right direction for handling them. I'll see about improving the example script later down the line to better demonstrate partial fill handling.

        Thanks for pointing out an area where it can be improved.
        JimNinjaTrader Customer Service


          I would like to add my thanks to Jim for providing his Unmanaged example strategy - very useful for anyone trying to make a start with this approach!

          I have a question, however. Just looking through the code, in OnOrderUpdate(), near the end where the stops and target orders are set to null, you comment :
          //PLEASE NOTE: setting IOrders to null ***DOES NOT*** cancel them
          , but give no further advise. Then at the end of the script there is a method called CancelAll() which cancels all orders, but this method is not called anywhere in the strategy, unless I totally missed something. Where would be the most appropriate place to put the CancelAll method in your script?

          If I want a strategy that placed new simultaneous LongStopLimit and ShortStopLimit orders on the first tick of every 15min bar to be concelled if unfilled on the close of the bar, then I guess the best place to cancel the them would be in OnBarUpdate() { OnFirstTickOfBar{ CancelAll() -> check for null, then SumbitOrderUnmanaged().

          Any thoughts or suggestions welcome!


            Hello ours_solaire,

            CancelAll() just shows a method that can be called to cancel all of the orders used in the strategy by checking if that order is null, and then calling CancelOrder(). Order objects should be set to null after cancellation or after a fill in OnOrderUpdate() so the order can be submitted again. This method is not called in this example and there is not a place where it should be called in the context of this example; the script is only meant to show how a basic unmanaged strategy can be written.

            If you are submitting new limit orders on every bar you could could call CancelOrder() for that order and resubmit, or you can call ChangeOrder() to update that order as needed.

            As a rough example:
            if (longEntry == null && shortEntry == null
                && Position.MarketPosition == MarketPosition.Flat)
                // Entry
            else if (longEntry != null && shortEntry != null
                && Position.MarketPosition == MarketPosition.Flat)
            	ChangeOrder(shortEntry, shortEntry.Quantity+1, Close[0]+EntryDistance*TickSize, 0);
            	ChangeOrder(longEntry, longEntry.Quantity+1, Close[0]-EntryDistance*TickSize, 0);
            Referencing the documentation for the methods and properties used in this strategy can help give further direction. I'll include links for ChangeOrder() and CancelOrder() below.

            CancelOrder() - https://ninjatrader.com/support/help...ancelorder.htm

            ChangeOrder() - https://ninjatrader.com/support/help...hangeorder.htm

            Please let me know if you have any questions.
            JimNinjaTrader Customer Service


              Hello Jim,

              Thanks for the prompt and detailed reply. I appreciate you taking the time to explain. I will definitely try your idea of using ChangeOrder() instead of cancelling and re-submitting the orders on each bar close - that option has the potential for more real-time problems than ChangeOrder() I'm guessing...


              Latest Posts


              Topics Statistics Last Post
              Started by dvcpro4, Yesterday, 07:08 PM
              1 response
              Last Post NinjaTrader_Marco  
              Started by chrismcdermut, Yesterday, 01:46 PM
              3 responses
              Last Post MojoJojo  
              Started by Bricolico, Yesterday, 09:28 PM
              0 responses
              Last Post Bricolico  
              Started by Tradwell385, Yesterday, 08:51 PM
              0 responses
              Last Post Tradwell385  
              Started by pennywise, Yesterday, 06:40 PM
              0 responses
              Last Post pennywise