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

Reverse Position with Stop Order and active StopLoss

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

    Reverse Position with Stop Order and active StopLoss

    The NT documentation states:
    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
    My situation is that I have a long position and want to set a stop market order to reverse and go short if the market hits the price but I also have an active stop loss in place. How can I perform this operation as NT doesn't allow it?

    My guess is one of 3 things:

    1) In OnOrderUpdate keep a reference to all stop loss order objects and cancel them out first. Then place my stop market order...but if price doesn't get hit within a certain timeframe then I must put my stoploss back in place.

    2) Handle placing stoploss orders manually ?

    3) Manage the trade in OnEachTick and wait for my predefined price to get hit then place an short market order?

    Is there another way to handle this situation? For example I'm long at 50, have a stoploss at 30 but later decide I need to reverse if the market hits 40 but only within a specific timeframe else keep my stoploss in place.

    #2
    Hello fxRichard,

    Thank you for your post.

    Your third option here would work for this purpose. Otherwise, you can switch to the Unmanaged Approach. The Unmanaged Approach is recommended for advanced programmers as you will need to handle the orders from start to finish, but it would allow for multiple orders that would not be possible in the Managed Approach.

    For information on the Unmanaged approach please visit the following link: http://ninjatrader.com/support/helpG...d_approach.htm

    Please let me know if you have any questions.

    Comment


      #3
      Thanks Patrick. I'm going the Unmanaged approach. Question about it that I can't find in the documentation.

      The OrderAction has Buy and BuyToCover (amongst others).

      If I am in a short position 1 contract and want to reverse it can I simply use OrderAction.Buy with a quantity of 2 or do I need to first do a BuyToCover and then another simply Buy order?

      Thanks.

      Comment


        #4
        Hello fxRichard,

        Thank you for your follow up.

        You should be able to do the action of buy for 2 quantity.

        Please let me know if you have any questions.

        Comment


          #5
          Thanks Patrick.

          I have setup a custom order handler class that handles all orders through the unmanaged approach. A question that arises is if I have a position of 1 contract long, I then want to reverse the position by selling 2 contracts, this leaves me in a position of 1 contract short.

          My code auto sets a stop market order for a hard stop loss no matter what the position is so if it is a reversal in this case I cancel out the original stop market stop loss order then submit a new one for the reversed order. To do this I need to know the order quantity so one would think I could simply do something like entryOrder.Quantity but in this case the quantity shows as 2. Can I access the actual position size of the order without having to store some data to keep track that this was a reversal etc?

          Comment


            #6
            My assumption is we should handle unmanaged stop loss orders by referencing the Position class instead of the entry order reference.

            Comment


              #7
              Originally posted by fxRichard View Post
              My assumption is we should handle unmanaged stop loss orders by referencing the Position class instead of the entry order reference.
              Thank you for your response, fxRichard.

              This is the route I would go as well. Utilize the Position updates to determine the size of the exit order(s). For information on Position please visit the following link: http://ninjatrader.com/support/helpG...s/position.htm

              Please let me know if you have any questions.

              Comment


                #8
                Originally posted by fxRichard View Post
                The NT documentation states:


                My situation is that I have a long position and want to set a stop market order to reverse and go short if the market hits the price but I also have an active stop loss in place. How can I perform this operation as NT doesn't allow it?

                My guess is one of 3 things:

                1) In OnOrderUpdate keep a reference to all stop loss order objects and cancel them out first. Then place my stop market order...but if price doesn't get hit within a certain timeframe then I must put my stoploss back in place.

                2) Handle placing stoploss orders manually ?

                3) Manage the trade in OnEachTick and wait for my predefined price to get hit then place an short market order?

                Is there another way to handle this situation? For example I'm long at 50, have a stoploss at 30 but later decide I need to reverse if the market hits 40 but only within a specific timeframe else keep my stoploss in place.
                That is the limitation in Ninja Trader unfortunately. Wish they change that. I use Multi Charts and face no issues or extra coding. It places the entry stop and if filled, will cancel open position and it's associated stop and target
                or leave position intact if stop entry is not hit.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by wzgy0920, 04-20-2024, 06:09 PM
                2 responses
                26 views
                0 likes
                Last Post wzgy0920  
                Started by wzgy0920, 02-22-2024, 01:11 AM
                5 responses
                32 views
                0 likes
                Last Post wzgy0920  
                Started by wzgy0920, Yesterday, 09:53 PM
                2 responses
                49 views
                0 likes
                Last Post wzgy0920  
                Started by Kensonprib, 04-28-2021, 10:11 AM
                5 responses
                191 views
                0 likes
                Last Post Hasadafa  
                Started by GussJ, 03-04-2020, 03:11 PM
                11 responses
                3,231 views
                0 likes
                Last Post xiinteractive  
                Working...
                X