Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How do I reverse a stop loss exit

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

    How do I reverse a stop loss exit

    Hi,

    I have an automated strategy with conditions that may create an entry long or short. How do I reverse the entry only when the stop loss is triggered and not when the profit target exits the position.

    Thanks for your help.

    Luis.

    #2
    Hello Luis,

    Thank you for your note.

    You would need to test for when the StopLoss order is filled in the OnExecution() method and then submit an order for the opposite direction.
    http://www.ninjatrader.com/support/h...nexecution.htm

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Luisfsz good morning,
      I need to do the same thing. I have to reverse at the time of the stop loss. Is it necessary to switch to unmanaged orders mode?
      could you post me the code you used to solve this situation?
      thank you very much

      Comment


        #4
        Hello marubozu79,

        Thank you for your post.

        To reverse your position after a stop loss is hit will require code that detects that either has been hit and then code that then enters an order in the desired direction; however, this may be done using the managed approach. You do not need to switch to unmanaged to achieve this.

        For the detection of an order execution you can look for the order name of Stop loss in OnExecutionUpdate()

        Here is an example of code that detects and prints what the order is:
        Code:
                 protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
                {        
                       if (execution.Name == "Stop loss")
                            Print(string.Format("{0} - Stop loss was filled", execution.Time));                        
                }
        You can use the above code to test the detection out as it will send the print statements to the output window (New > NinjaScript Output).

        With the above code you can then add logic to your code to then enter an opposite direction order from within OnExecutionUpdate() if the filled order was a stop loss.

        Please let us know if we may be of further assistance to you.
        Last edited by NinjaTrader_Kate; 04-14-2020, 02:14 PM. Reason: code displaying improperly

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        599 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        345 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        558 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        558 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X