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

SubmitOrderUnmanaged Orders Ignored in Real-time Paper Trading

Collapse
X
 
  • 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].
    Code:
    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.

    #2
    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

    Comment


      #3
      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
      Thanks

      Comment


        #4
        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

        Comment


          #5
          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!

          Comment


            #6
            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:
            Code:
            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

            Comment


              #7
              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...

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by jclose, Today, 09:37 PM
              0 responses
              5 views
              0 likes
              Last Post jclose
              by jclose
               
              Started by WeyldFalcon, 08-07-2020, 06:13 AM
              10 responses
              1,414 views
              0 likes
              Last Post Traderontheroad  
              Started by firefoxforum12, Today, 08:53 PM
              0 responses
              11 views
              0 likes
              Last Post firefoxforum12  
              Started by stafe, Today, 08:34 PM
              0 responses
              11 views
              0 likes
              Last Post stafe
              by stafe
               
              Started by sastrades, 01-31-2024, 10:19 PM
              11 responses
              169 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Working...
              X