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

SetStopLoss and Reverse in Managed Approach

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

    SetStopLoss and Reverse in Managed Approach

    Hey guys,

    Question.. can you use SetStopLoss to reverse your position if it's hit while using the Managed Approach? Let's say if I set a Buy Stop Market order above a bar and SetStopLoss below that bar with a SetProfitTarget some distance away. Once the Long order is taken in, if it hits the SetStopLoss, it would automatically go into a Short with a new SetStopLoss and SetProfitTarget.
    Is this doable?

    #2
    Hello PN720,
    Thanks for your post.

    This is certainly doable. I have attached a sample that demonstrates how your SetStopLoss() and SetProfitTarget() methods will cancel and resubmit appropriately when switching positions like this. Just run the strategy and wait 5 bars for the strategy to switch positions. You should see the protective orders get canceled and new ones submitted with the new position.

    Help Guide - SetStopLoss()

    Let me know if you have any questions.
    Attached Files
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Hi Josh,

      Thank you for the example.

      It seems to me that the orders will reverse if you are in a Long position and you EnterShort. However, my scenario would be if I'm entering with a Buy Stop and the order will reverse when the StopLoss is hit. How would I do that?

      Comment


        #4
        PN720,

        In my sample it is switching from long to short, and because of that the stop and target changes. (not the other way around). NinjaTrader is not going to reverse just because your stop loss is hit, unless you have specifically coded your logic that way.

        You would need to run some logic through OnExecutionUpdate to see if the stop loss was hit and then run your other logic. Here is a reference sample on how to track your orders using OnOrderUpdate() and OnExecutionUpdate(). You should be able to modify this sample to fit your needs.




        Josh G.NinjaTrader Customer Service

        Comment


          #5
          Josh,

          Just so I understand correctly, there's not an easy way without coding using the OnExecutionUpdate to detect if the Stop Loss has been hit and then submitting another order going the other way.
          The functionality I'm looking is how an ATM works currently if 'Reverse At Stop' is checked but I want to do it through a Strategy.

          Or if I'm on the Chart Trader and doing this manually, if I'm in a Long with 1 Contract and set a Sell Stop with 2 contracts so if it's hit, it will close out the current one and enter Short with the remaining 1 contract.

          Comment


            #6
            PN720,

            You are understanding correctly. You'll need to create the logic for that behavior to occur, and I believe OnExecution will be the place to start.

            Please let me know if you have any questions.
            Josh G.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by bortz, 11-06-2023, 08:04 AM
            47 responses
            1,603 views
            0 likes
            Last Post aligator  
            Started by jaybedreamin, Today, 05:56 PM
            0 responses
            8 views
            0 likes
            Last Post jaybedreamin  
            Started by DJ888, 04-16-2024, 06:09 PM
            6 responses
            18 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            4 views
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            13 views
            0 likes
            Last Post Javierw.ok  
            Working...
            X