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

Reversing with Managed Approach

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

    Reversing with Managed Approach

    Hi,

    I'm studying the Internal Order Handling Rules and I'm not quite following all the detail. Let me give you a simple example of what I would like to accomplish.

    Let's say my strategy is short 1 contract. To provide some context: the market is moving against me, and eventually, my long signal triggers. Ideally, this long signal would submit a EnterLongLimit(1), thus making the strategy long 1 contract in the even that the Limit order was executed.

    If I avoid using any SetStopLoss or SetProfitTarget, would such an order reverse me correctly? Or must I go the Unmanaged route? If so, it sure would be nice if there was some sample strategies in the forum to work from

    Thanks.

    #2
    Hello,

    Your understanding is correct.


    If you were short 1 contract and your long signal triggers, EnterLongLimit for 1 would place 2 limit order, one 1 exit the position and another to enter the new long position.
    MatthewNinjaTrader Product Management

    Comment


      #3
      This doesn't seem to be working for me.

      In my case, I have a short entry order called "d-short" running, and it has an active ExitShortStop() and ExitShortLimit() on it. The strategy gets triggered with a long signal and tries to place a EnterLongStopLimit() order called "t-long". I get a message in the output window saying this order was ignored.

      Indeed, the documentation page http://www.ninjatrader.com/support/h...d_approach.htm says that an entry order opposing an existing position will be ignored if there's an Exit() method active. But it says this is supposed to be true per unique signal name.

      In my strategy I have two kinds of signals, "d" and "t". They are generated by completely different rules. Each may generate entries in the same direction or in opposing directions. If a signal occurs to oppose an existing position, I want the position reversed if the order is filled. How would I reverse the position in this case?

      -Alex

      Comment


        #4
        Are just the exit signals uniquely tagged as well? What are you using for the string fromEntrySignal on the exit methods?
        MatthewNinjaTrader Product Management

        Comment


          #5
          My entry orders are named either d-long, d-short, t-long, or t-short.

          Each entry order, once filled, causes OnExecution() to generate two exit orders, a limit and a stop for profit target and stoploss, respectively.

          Each exit order has the same name as the associated entry, prefixed by xt or xs, to signify "exit target" or "exit stoploss".

          Each exit order has the FromEntrySignal property set to the name of the entry order.

          So I have a situation where a 'd-short' position is active along with its associated exits 'xtd-short' and 'xsd-short'. Then the strategy gets another signal and needs to place a stop limit order 't-long', and adjust the earlier 'xsd-short' exit to the same price as the new long entry price. That way when both are filled, the position is reversed, the old 'xtd-short' target exit is cancelled because the 'd-short' position no longer exists, and new exit orders are generated for the new 't-long' position.

          That's how I want it to work, but the strategy is unable to place that new entry order. If the fix involves simply changing my order naming scheme, that's fine if I knew what to do.

          If I'm doing this in real time, I'd have two DOM windows open, each displaying the selected ATM strategy only, and I'd set the exit order in one DOM to equal the opposing entry order in the other DOM, which effectively reverses the position when both orders fill. I can't seem to do that with the managed approach in my strategies -- any attempt to place a new order is ignored.

          -Alex
          Last edited by anachronist; 07-25-2012, 10:41 AM.

          Comment


            #6
            The target/stops will need unique signal names just as you are using for the entry orders. If an existing target with a signal name exists, and a new position is opened on another entry signal, the new target would be ignored as the signal name is already being used.
            MatthewNinjaTrader Product Management

            Comment


              #7
              But they are unique. In the example above:
              • Entry order 'd-short' is filled.
              • The short position has two exit orders named 'xsd-short' and 'xtd-short', both with FromEntrySignal='d-short'.
              • A new stop-limit entry order 't-long' is placed while the short position is active. There is no target and stop exit for this new entry yet; that happens after it fills.
              • NinjaTrader ignores the new entry order.

              Where, in the list above, are any names being re-used? The new entry order 't-long' does not re-use any signal name in the open position.
              -Alex
              Last edited by anachronist; 07-25-2012, 11:34 AM.

              Comment


                #8
                Can you please provide me with samples from your code to prevent any further confusion. I would be happy to review what is occurring and provide steps to avoid the ignored orders.


                What is the exact text from the log regarding the ignored order?
                MatthewNinjaTrader Product Management

                Comment


                  #9
                  I'll try to distill my code down to something I can post.

                  The exact text is "An Enter() method to submit an entry order at '10/10/1997 13:00:00' has been ignored. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation."

                  That part of the help guide is at http://www.ninjatrader.com/support/h...d_approach.htm under the heading "Internal Order Handling Rules that Reduce Unwanted Positions", where it says:
                  Methods that generate orders to enter a position will be ignored if:
                  • A position is open and an order submitted by an exit method (ExitLongLimit() for example) is active and the order is used to open a position in the opposite direction
                  • A position is open and an order submitted by a set method (SetStopLoss() for example) is active and the order is used to open a position in the opposite direction
                  • 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
                  • The entry signal name is not unique
                  Only the first bullet above seems applicable here. I'm not using any Set method, the strategy position isn't flat, and my signal names for the opposing entries are unique.

                  A short position is running, orders submitted by ExitShortLimit() and ExitShortStop() are active, and I try to submit a long entry order opposing the current position. The first bullet above says the entry order will be ignored, and indeed it is.

                  It seems the only way to get around this restriction is to cancel my exit orders prior to placing the new entry order, but that could be disastrous if the new entry never fills and the old position is left dangling without any exit orders.

                  -Alex
                  Last edited by anachronist; 07-25-2012, 12:08 PM.

                  Comment


                    #10
                    Originally posted by anachronist View Post
                    I'll try to distill my code down to something I can post.

                    The exact text is "An Enter() method to submit an entry order at '10/10/1997 13:00:00' has been ignored. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation."

                    That part of the help guide is at http://www.ninjatrader.com/support/h...d_approach.htm under the heading "Internal Order Handling Rules that Reduce Unwanted Positions", where it says:

                    Only the first bullet above seems applicable here. I'm not using any Set method, the strategy position isn't flat, and my signal names for the opposing entries are unique.

                    A short position is running, orders submitted by ExitShortLimit() and ExitShortStop() are active, and I try to submit a long entry order opposing the current position. The first bullet above says the entry order will be ignored, and indeed it is.

                    It seems the only way to get around this restriction is to cancel my exit orders prior to placing the new entry order, but that could be disastrous if the new entry never fills and the old position is left dangling without any exit orders.

                    -Alex
                    There are quite a few threads on these boards that discuss this very issue. The answer seems to always be to switch to the unmanaged approach, and handle all the possible error states yourself.

                    Comment


                      #11
                      Originally posted by koganam View Post
                      There are quite a few threads on these boards that discuss this very issue. The answer seems to always be to switch to the unmanaged approach, and handle all the possible error states yourself.
                      Eh. I guess I can do that. I've already written a trade management framework that uses the unmanaged approach to simulate ATM strategies in backtest, then switches over to actual ATM strategies on live data. In this particular case, however, it just didn't seem practical to use ATM on weekly price data, especially when a different exit strategy is required for nearly every trade.

                      I find it odd that the managed approach can't simply exit one position and cancel all exit orders associated with it when a trade in the opposite direction is executed. That's kind of a basic no-brainer functionality.

                      -Alex

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by ETFVoyageur, Today, 05:50 AM
                      4 responses
                      23 views
                      0 likes
                      Last Post ETFVoyageur  
                      Started by ESHunter, Yesterday, 08:06 PM
                      3 responses
                      26 views
                      0 likes
                      Last Post NinjaTrader_BrandonH  
                      Started by jrp2099, Today, 08:01 AM
                      0 responses
                      2 views
                      0 likes
                      Last Post jrp2099
                      by jrp2099
                       
                      Started by sofortune, 05-10-2024, 10:28 AM
                      5 responses
                      34 views
                      0 likes
                      Last Post NinjaTrader_Erick  
                      Started by thumper57, 05-11-2024, 04:30 PM
                      11 responses
                      35 views
                      0 likes
                      Last Post thumper57  
                      Working...
                      X