Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Clarification around life cycle/duration of managed orders

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

    Clarification around life cycle/duration of managed orders

    Hi,

    As I've been reading through the help, I believe I've come across conflicting descriptions of the life cycle/duration of managed orders. On the one hand, I believe I've read that if a managed order is not filled on the bar on which it was entered, it is canceled. HOwever, I also read the below, which indicates that an order lives as long as it is constantly refreshed in every call to OnBarUpdate()
    Orders are primarily submitted from within the OnBarUpdate() method when a specific order method is called. By default, orders are kept alive, provided they are re-submitted on each call of the OnBarUpdate() method. If an order is not re-submitted, it is then canceled.

    Let's say you're using Renko bars and at the first tick of a bar, you enter a stop order above where you know it's high is going to be if the bar closes up. You only want a fill on the current bar, not a subsequent bar. The order would be based on:

    EnterLongStopMarket(<my stop price>)

    The order will or won't be filled depending on where price goes during the current bar. Do I enter the order once, knowing it will be canceled if a new bar forms and the order is still open, or, do I reenter the order on every call with every tick to OnBarUpdate(), per the above? If I reenter the order on every call to OnBarUpdate(), then I assume I have to track whether or not I'm still on the bar on which I want to order to be filled or to be canceled. It's a bit confusing. If someone from the Ninja team could please clarify exactly how the lifecycle of a managed order works, and what the strategy developer has to do to properly work with that, I would appreciate it.

    Regards,

    Gordon

    #2
    Hi Gordon, thanks for your post.

    The order method does not need to be called on every tick of OnBarUpdate when your strategy is running OnEachTick or OnPriceChange. One would need to keep track of the bar with the CurrentBar property. CurrentBar will tell you what bar index you are on from the very leftmost bar on the chart.

    All order entry methods have a special override that allows you to keep the bar alive e.g. EnterLongStopMarket(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double stopPrice, string signalName)

    If you want to look into advance order handling we have a good example here:

    https://ninjatrader.com/support/help...and_onexec.htm

    Please let me know if I can assist any further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi Chris,

      Thanks for your response. My understanding now is that if you enter a managed order on a given bar, using say EnterLongStopMarket(<my stop price>) where CurrentBar = 100, and then bar 100 closes and bar 101 starts without the order having fired, then NinjaTrader will automatically cancel the order. Is that correct?

      And, does all of this apply to AtmStrategyCreate(), or is it necessary to explicitly call AtmStrategyCancelEntryOrder() to cancel an order entered using AtmStrategyCreate()? The help seems to be clear that AtmStrategyCreate() is a different animal and that it's necessary to manage it manually, but wanted to be sure.

      - Gordon
      Last edited by grose; 03-31-2020, 04:21 PM.

      Comment


        #4
        Hello Gordon,

        Yes, in NinjaScript managed strategy when isLiveUntilCancelled is false, or is not used (which defaults to false), working orders are cancelled when the submission bar closes.
        Calling the entry method again with the same signalName will keep the order alive.

        This does not apply to Atm Strategy methods. Orders placed through these methods are not placed to the strategy and do not affect the strategy performance or position and are not automatically cancelled when the bar closes.
        Orders placed through Atm Strategy methods are basically the same as a manually placed order.
        https://ninjatrader.com/support/help...strategies.htm
        https://ninjatrader.com/support/help...gy_methods.htm
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks, Chelsea. It looks like what I want is something between a managed order and atmstrategycreate. Just a couple more questions will help know which way I need to go. Some of these may still be a bit on the newbie side of things with respect to developing strategies in NT8.

          - if on a chart, where a managed stop loss order has been placed by your strategy, if you manually adjust the order on the chart using your mouse, does that cause the strategy to terminate? In NT7, you couldn't interfere with orders placed by a strategy.

          - the strategy based on managed orders that I would want to create and that would be equivalent to using atmstrategycreate would have an entry order for two contracts. For one of them, I would have a set stop loss and profit target. For the second, I would only want a stop loss. I would either manage the stop in code, or ideally, manage it on the screen (and that's a reason for the first question). What I'm not clear on is that SetStopLoss() and SetProfitTarget() dont seem to support a quantity that would allow me to create one pair of those orders for one of the two contracts, and a different pair for the second. I suppose I could create two orders for the two contracts, each with a different name that could be used. But that's a lot to keep track of. Do you any thoughts or suggestions for achieving this scenario?

          Thanks,

          Gordon


          Comment


            #6
            Hello Gordon,

            Clicking the Close button causes NinjaScripts to be disabled, errors cause NinjaScripts to be disabled. Moving a script that has set methods (or code that updates the prices of exit orders) will move those orders back to the original prices after the user has moved them.

            Modifying a price of an order does not cause a NinjaScript to be disabled.

            Scaling in and out with or without a profit target can be achieved either way. Using Atm Strategy methods is more advanced.
            https://ninjatrader.com/support/foru...80#post1077380
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thanks, Chelsea. I'll study your example.

              Comment


                #8
                I enter the order once, knowing it will be canceled if a new bar forms and the order is still open, or, do I reenter the order on every call with every tick to OnBarUpdate(), per the above? If I reenter the order on every call to OnBarUpdate(), then I assume I have to track whether or not I'm still on auto clicker the bar on which I want to order to be filled or to be canceled. It's a bit confusing.
                Last edited by rafaelabe1977; 04-09-2020, 08:46 PM.

                Comment


                  #9
                  Hello rafaelabe1977,

                  Welcome to the NinjaTrader forums.

                  When using Calculate.OnEachTick an order can be kept alive by re-submitting when IsFirstTickOfBar is true.
                  https://ninjatrader.com/support/help...ttickofbar.htm

                  Orders are cancelled when the bar the order is submitted to is closed.

                  When Calculate is .OnBarClose orders are submitted after the most recent bar fully closes, and that order will be submitted to the newly opened bar as it opens.
                  Chelsea B.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by bjgjkhjuhgtybg, Today, 04:38 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post bjgjkhjuhgtybg  
                  Started by varun12343, Today, 03:09 AM
                  1 response
                  8 views
                  0 likes
                  Last Post NinjaTrader_Marco  
                  Started by Lance El Camino, Yesterday, 04:14 PM
                  2 responses
                  24 views
                  0 likes
                  Last Post NT-Roland  
                  Started by MatthewLesko, Yesterday, 11:13 PM
                  1 response
                  14 views
                  0 likes
                  Last Post NT-Roland  
                  Started by kevinenergy, Today, 01:44 AM
                  0 responses
                  7 views
                  0 likes
                  Last Post kevinenergy  
                  Working...
                  X