Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trailing Stop Problem…

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

    Trailing Stop Problem…

    Dear NT Gurus,

    I have been struggling recently to implement a strategy with first a stop and then a trailing stop, I am desperately looking for help.

    I read all the posts on the forum I could find on trailing including the Tips often referenced on trailing questions but I am still stuck (Due to the number of posts on trailing it seems I am not the only one having difficulty using it.).

    It could be worth mentioning that I am using the OnOrderUpdate and OnExecution to monitor my strategy. Very few examples are using these methods which doesn't help!

    The logic could be summarized like this
    1) When we have en entry set a stop loss and a profit target
    2) When the profit target is hit cut the position in 2, i.e. take a profit.
    3) Cancel the stop loss and replace it with a trailing stop. The trailing starts at break-even.

    In more detailed it works like this

    1) OnBarUpdate fires the entry when the condition is met.
    entryOrder = EnterLongStop(0, true, quantity, Entry, "Entry");

    2) OnExecution will be called after the entry has been executed. When called, set a stop and the first target

    stopOrder = ExitShortStop(0, true, execution.Order.Filled, Stop, "Stop", "Entry");

    targetOrderX1 = ExitShortLimit(0, true, execution.Order.Filled/2, X1, "Target1", "Entry");

    3) OnExecution will then either be called if the stop is hit or if targetOrderX1 is executed.

    if targetOrderX1 is executed I cancel the stop with
    CancelOrder(stopOrder);
    and create the trailing order
    SetTrailStop("Entry", CalculationMode.Ticks, RiskPoint , false);

    Is their a flaw in the design? Is it supposed to work like this, i.e. attaching a trailing after an execution?

    It seem that if the trailing is executed, the strategy stops working. The trailing order is executed (closing the position) but “position.ToString()“ still say I am long or short.

    Post

    was similar to what I am trying to achieve but the link in post 2 doesn’t work anymore.

    I remember having read a post from a NT Team member saying that an example will soon be posted but it never was.

    Any help would be greatly appreciated. I was wondering if the NT Team could not release an official 2 phases scaling out example using OnOrderUpdate and OnExecution.

    Thanks in advance.
    Amiral

    #2
    Hi Amiral,

    1) OnBarUpdate() submission of your entry order looks good.
    2) You need to be a little careful here. If you have partial fills, ensure you are tracking the correct order and submitting protective orders as necessary. Also, due to race conditions you will want to use execution.Filled instead of execution.Order.Filled.
    3) Again, just make sure you are watching for the execution.Name to match your order name when you do this instead of expecting a certain sequence.

    Let us say your profit target was filled here. To switch your stop loss over to a trailing stop you do not need to cancel your stop loss. Reason you cannot use SetTrailStop() is because once you declare it it will use that automatically for every entry order in the future. This will result in some Internal Order Handling Rules being violated in the future. Instead you want to manually program the trail logic within the OnBarUpdate() once you determine it is time to switch over to a trailing stop style. This will be done just by modifying your current ExitShortStop() order instead of cancelling it.

    Please check out the end of this thread here for some ideas on how to program this logic: http://www.ninjatrader-support.com/v...ad.php?t=10344

    Hope this helps.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Josh,

      Thanks for your prompt answer and genuine support.
      With the help of the sample you gave I have been able to implement the proper position management.

      I was wondering if the NT team could not, for the general interest, add in the Tips section a complete strategy example of a 2 steps scaling out position using a trailing stop (preferably using OnOrderUpdate and OnExecution). This example could serve as a best practice example.

      The use of SetTrailStop() is not that obvious and documentation could probably be extended a bit on this subject.

      Anyway… just food for thoughts.
      Kind Regards,
      Amiral

      Comment


        #4
        Hi Amiral,

        Thank you for the suggestion. I will forward them up.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Hi

          You wrote in a post below:
          Reason you cannot use SetTrailStop() is because once you declare it it will use that automatically for every entry order in the future
          Can I not start a trailingstop as follows:
          SetTrailStop(EnterOrderName, CalculationMode.Percent , 0.05, false);
          In this case the trailingstop is bound to the trade opened as "EnterOrderName". And any new future trade will *not* have a trailing stop.
          Or do I overlook something?

          regards
          Andre

          Comment


            #6
            Andre, if the future trade has the signal EnterOrderName, then it too will have a trailing stop. If you named it something else, there would not be a trail stop.
            AustinNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Austin View Post
              Andre, if the future trade has the signal EnterOrderName, then it too will have a trailing stop. If you named it something else, there would not be a trail stop.
              sure, I take for each trade a different name and therefore I have a trailstop for each trade.

              Comment

              Latest Posts

              Collapse

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