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

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
        Kate W.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cre8able, Today, 01:16 PM
        2 responses
        9 views
        0 likes
        Last Post cre8able  
        Started by chbruno, 04-24-2024, 04:10 PM
        3 responses
        48 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by samish18, Today, 01:01 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by WHICKED, Today, 12:56 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by WHICKED, Today, 12:45 PM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X