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

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.
    Chris L.NinjaTrader Customer Service

    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.
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Felix Reichert, 04-26-2024, 02:12 PM
        11 responses
        72 views
        0 likes
        Last Post Felix Reichert  
        Started by junkone, 04-28-2024, 02:19 PM
        7 responses
        80 views
        1 like
        Last Post junkone
        by junkone
         
        Started by pechtri, 06-22-2023, 02:31 AM
        11 responses
        136 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by ageeholdings, 05-01-2024, 05:22 AM
        4 responses
        27 views
        0 likes
        Last Post ageeholdings  
        Started by hdge4u, 04-29-2024, 12:23 PM
        4 responses
        23 views
        0 likes
        Last Post NinjaTrader_RyanS  
        Working...
        X