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

How to submit new managed order on close of bar

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

    How to submit new managed order on close of bar

    I understand (and see when I run my strategy) that if I submit an entry stop or limit order in OnBarUpdate, and the next bar closes without a fill, then the entry order gets canceled. But in my OnBarUpdate method, I can see that there was no fill and I try to enter a new entry stop or limit order. What happens is that after this, in OnOrderUpdate, I get notified that the prior entry order is canceled. The new entry order however seems to just sit there - I never get any notification in OnOrderUpdate that anything has happened to that order. I never see it on my chart - I never hear "order submitted" audio coming from my platform. So it seems that the code to enter the new order gets called but the order just sits in limbo or gets ignored.

    What I want to do is the following:
    I want to submit an entry stop or limit order in OnBarUpdate as long as I am Flat. If the bar closes with no fill, I would like to submit a new entry order based on the bar that just closed with no fill. That doesn't seem to work now, how can I make it work?

    Note: when I enter via stop or limit, I also set a stoploss and target some number of pips away. If the order fills and closes, I can indeed submit a new order at the end of the bar where it clloses. In other words, something is not working if the order gets canceled, but it DOES work if the order gets filled and closed.

    How do I fix this?

    UPDATE: Ok, it seems that if I resubmit the order (using say the same call to EnterLongStopMarket or EnterLongLimit with perhaps a modified price) it all works fine. The entry is not canceled but is instead moved to the sam price. But If I want to enter an order in the OPPOSITE direction it does not work! So for example, if I submit an EnterLongStopMarket and that does not fill, on the next call to OnBarUpdate I try to enter a EnterShortStopLimit. That order just sits there and never does anything (or is rejected, I'm not sure). The originall buy stop market is canceled and the new sell stop market doesn't ever appear anywhere.

    How to fix?
    Last edited by westofpluto; 10-09-2020, 02:00 PM.

    #2
    Hello westofpluto,

    Thank you for your note.

    The first thing I would recommend would be to turn on the Order Trace function to see what's occurring:

    Strategy Builder > Default Properties > More Properties > Trace Orders, or:

    if (State == State.SetDefaults)
    {
    TraceOrders = true;
    }

    Once you then recompile the strategy, you can open a new NinjaScript Output window under New > NinjaScript Output. This will print a log of any orders submitted by the strategy during while it's running, along with any ignored orders. You can then look through and see what may be occurring.

    Here is a link to our help guide that goes into more detail on tracing orders:
    https://ninjatrader.com/support/help...aceorders2.htm

    Trace orders alone may not give you the full picture of whether or not a trade should have been entered on a given bar, so adding prints to your strategy that will show in the NinjaScript Output window, with information on what the variables you're using for your conditions are on a particular bar, can be helpful.

    This forum post goes into great detail on how to use prints to help figure out where issues may stem from — this should get you going in the correct direction. You can even add these using the Strategy Builder.

    https://ninjatrader.com/support/foru...ns-not-working

    If you run into issues like we saw here, the above information will allow you to print out all values used in the condition in question that may be evaluating differently. With the printout information you can assess what is different between the two.

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

    Comment


      #3
      Kate I know how to debug and how to use Print statements. Your response does not answer the question.
      What I don't know is why I can't enter an opposite order if the order is canceled until the bar after it was canceled. In other words:
      If I enter an order in one direction and that does not fill, in OnBarUpdate I can submit a new enttry which resubmits the old entry in the same direction. That works. BUT
      If I try to enter an order in the opposite direction after an order in the first direction gets canceled, it does not work. My opposite order just sits there - no OnOrderUpdate calls, no warning messages, nothing.

      Why is that? This has to be a Ninjatrader issue or setting. Please ask your colleagues if you are not sure.

      Comment


        #4
        So I found this statement in discussions on NinjaTrader internal order entry rules:
        An entry order will be ignored for various reasons including:
        The strategy position is flat and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction

        So it appears that in OnBarUpdate I probably have to explicitly call CancelOrder() on the entry order that is about to cancel anyway and then call the method to enter in the opposite direction.

        Comment


          #5
          Hello westofpluto,

          Thank you for your reply.

          Have you then tried using TraceOrders to determine if the order is being ignored as I suggested?

          It sounds like the order is likely being ignored due to order handling rules:

          The strategy position is flat and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction


          Using the managed approach, you'd need to wait until the next bar after the previous bar to submit the new order, or it would be ignored. You could use the unmanaged approach instead, however, please be aware that this approach should only be used by very experienced programmers as it would require you to create your own code to manage order rejections and other issues:



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

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by arvidvanstaey, Today, 02:19 PM
          4 responses
          11 views
          0 likes
          Last Post arvidvanstaey  
          Started by samish18, 04-17-2024, 08:57 AM
          16 responses
          61 views
          0 likes
          Last Post samish18  
          Started by jordanq2, Today, 03:10 PM
          2 responses
          9 views
          0 likes
          Last Post jordanq2  
          Started by traderqz, Today, 12:06 AM
          10 responses
          18 views
          0 likes
          Last Post traderqz  
          Started by algospoke, 04-17-2024, 06:40 PM
          5 responses
          48 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X