Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop Loss and Take Profit with Strategy using Stop Market Entry Orders

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

    Stop Loss and Take Profit with Strategy using Stop Market Entry Orders

    Hi!

    I want to implement a Stop Loss in a strategy which uses Stop Market Entry Orders. These Entry Orders sometimes also reverse the position.

    I am submitting ExitLongStopMarket every bar as long as the position is long and vice versa for the short side to make the Stop Loss work. However, with this approach the strategy sometimes ignores my Entry orders when the entry order reverses the position. What can I do to avoid this?

    I am aware of the Internal Order Handling Rules to reduce unwanted positions but how can I solve this problem?

    Thanks in advance!

    #2
    Hello, thanks for writing in. You can not have an entry order going in opposite directions at the same time using the managed approach. One of these rules is causing the order to be ignored:

    Code:
    Methods that generate orders to enter a position will be ignored if:
    
    •A position is open and two or more Entry methods to reverse the position are entered together. In this case the second Entry order will be ignored.
    
    •The strategy position is flat and an order submitted by an enter method ([URL="https://ninjatrader.com/support/helpGuides/nt8/enterlonglimit.htm"]EnterLongLimit()[/URL] for example) is active and the order is used to open a position in the opposite direction
    
    ​
    Your code needs to make sure its not breaking one of these rules so the entry order is not ignored.

    Comment


      #3
      Thanks for the prompt response.

      Just to make sure you understood my question: I think the following rule is the problem:

      Code:
      Methods that generate orders to enter a position will be ignored if:
      
      •A position is open and an order submitted by a non market order exit method ([URL="https://ninjatrader.com/support/helpGuides/nt8/exitlonglimit.htm"]ExitLongLimit()[/URL] for example) is active and the order is used to open a position in the opposite direction
      ​
      Eg. I am in a long position and have an ExitLongStopMarket and a EnterShortStopMarket. The EnterShortStopMarket is ignored because the ExitLongStopMarket is active. I think this is the problem.

      I tried cancelling the ExitLongStopMarket Order in OnBarUpdate before EnterShortStopMarket but this doesn't work. How can I make sure not to break these rules? I mean the benefit of Stop Entry Orders is not to calculate the full code on each tick. But I don't see a way to code this unless calculating on each tick and submitting only market orders and not stop orders.

      It is really strange that such a "simple" trading strategy is not possible with the managed approach. I mean the managed approach with stop and limit entry orders is useless if I cannot reverse the position only because I have a Stop Loss implemented. I think almost any trader will have a Stop Loss on any strategy. If there is a request on making this possible please add my vote to it.
      Last edited by KirkHammett; 04-26-2023, 08:16 AM.

      Comment


        #4
        Hi Kirk, You will need to use OnOrderUpdate to ensure the order reaches the Canceled state before submitting the next order. We have a couple of related examples here:




        To avoid this kind of complexity, you will need to run your script OnEachTick and use market orders, which makes reversals quite easy, see the SampleMACrossover for an example. All you need to do is call the opposing Entry order to reverse while in a position. E.e. while in a Long position, call EnterShort(), then NinjaTrader will close the long position and enter short automatically.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        25 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        121 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        64 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        41 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X