Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetTrailStop() never closes position

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

    SetTrailStop() never closes position

    Hi NT Support,

    In my strategy backtested using 30 min. historical data I set up trailing stop like that in OnBarUpdate():

    Code:
    if (Position.MarketPosition == MarketPosition.Long && trailingStop == false && Close[0] - entryOrderLong2.AvgFillPrice >= 200*TickSize) {
                    SetTrailStop("MyEntryLong2", CalculationMode.Ticks, 10, false);    // Trailing stop orders are modified in real-time and NOT on the close of a bar.
                    trailingStop = true;
    }
    Finally:

    Code:
    protected override void OnPositionUpdate(IPosition position) {
              Print(Time[0] + " OnPositionUpdate(): " + position.ToString());
              if (position.MarketPosition == MarketPosition.Flat) {
                trailingStop = false;
              }
    TrailStop executes properly:

    Code:
    2009-04-16 02:30:00 Entered internal SetStopTarget() method: Type=TrailStop FromEntrySignal='MyEntryLong2' Mode=Ticks Value=10 Currency=0 Simulated=False
    but never fills (never closes my long market position) -although should.

    What can be wrong?

    #2
    Argo1, can you please post the complete code you're using? At first glance, everything looks fine but the conditions for setting the trail stop are a bit restrictive.

    In case you haven't seen it, here is the help guide page for SetTrailStop().
    AustinNinjaTrader Customer Service

    Comment


      #3
      I can't publish this strategy.
      What about conditions? Conditions for execution are met - 200 pips profit on opened position. Next bars goes down - then trailing stop loss should be activated.
      At the same moment I set up stop loss for another position, and it's filled few bars later - trailing stop should act at the the same or next bar.
      Probably there is something with internal trailstop processing?

      Comment


        #4
        In Control Center Log I found about this TrailStop order:
        Code:
        A Set() method to   submit an exit order at '2009-04-16 02:30:00' has been ignored. Please search   on the term 'Internal Order Handling Rules' in the Help Guide for detailed   explanation.
        My opened order is not limit/stop order (is market) and I do not use SetStopLoss() nor exit/stop limit orders with this order.
        Last edited by Argo1; 10-29-2009, 06:30 PM.

        Comment


          #5
          I found what makes that error:
          I have opened ExitLongStop order in OnBarUpdate(), but for another market order, and is identified by unique fromEntrySignal.

          It would be very bad if NT has such a limitations!

          Code:
          stopOrderLong1 = ExitLongStop(0, true, entryOrderLong1.Quantity, entryOrderLong1.AvgFillPrice, "MyStopLong1", "MyEntryLong1");
          Last edited by Argo1; 10-29-2009, 07:09 PM.

          Comment


            #6
            With this you're running in NinjaTrader's Internal Order Handling Rules as noted in the Trace orders output you got - http://www.ninjatrader-support.com/H...verview36.html (please review the botton section of this link)

            NinjaTrader 7 will offer an unmanaged order submission approach giving your more flexibility - http://www.ninjatrader.com/webnew/NT7/NinjaTrader7.html

            New Unmanaged Order Submission
            In 6.5 some users were burdened with our "Internal Order Handling" rules. We have introduced unmanaged order submission which bypasses the convenience of our order handling layer. This lower level of programming allows you to do what you want relative to order submission/management without any limitations other than any imposed by your broker. There are only three methods, SubmitOrder(), ChangeOrder() and CancelOrder(). You then get the flexibility of managing your orders how you see fit and optionally handling rejections.

            Comment


              #7
              It's very frustrating, that I cannot even write my first strategy because of product limitations. I thought that NT is mature and professional tool for strategy building. It's very surprising that I can't make tradeable algorithm that could be run in real life environment.
              I hear about NT7 from months and I cannot wait ad infinitum.

              I am suggesting to look at MetaTrader architecture - it is such a functional solution for strategies building (but unfortunately I can't use it with Interactive Brokers).


              I read your documentation many times earlier.
              And my order to which I attach SetTrailStop() order is not submitted by exit method -it is submitted only by EnterLong(). My other order submitted at the same time is submitted by exit method. Even in this situation IOHR limits works?

              Set() methods that generate orders to exit a position will be ignored if a strategy position is open and:
              • An order submitted by an enter method (EnterLongLimit() for example) is active and this entry order is used to open a position in the opposite direction
              • An order submitted by an exit method (ExitLongLimit() for example) is active
              So, what's the workaround? Manually submit ExitStopLong() after each bar? It has one disadvantage - this "trail stop" won't work during first bar.

              Comment


                #8
                Argo1, I'm not sure I follow exactly what you're doing here, so let's break it down -

                1. Are you attempting to work with a SetStopLoss and SetTrailStop on the same position -> unfortunately this is not supported, work with SetStopLoss then and trail it's value as needed.

                2. Or do you have an Exit() method working while attempting to trail with SetTrailStop? This would then results in running into the IOHR as noted in the link I posted. Workaround in those cases it to monitor price and only submit one order simulatenously then.

                Comment


                  #9
                  I have 2 opened positions at the same time in the same direction.

                  Ad.1
                  No. I want to attach TrailStop to first opened market position. I don't use any SetStopLoss() functions.
                  But I cannot do that because I have second market position with ExitStopLong() pending order. This exit stop order causes order handling error.

                  Ad.2
                  No. I don't have any pending orders related to my first market position. I only want to set trail stop for it.

                  Problem is because I have 2 positions opened at the same time and second one has ExitStopLong() pending order. They are not related each other but IOHR error occurs
                  Last edited by Argo1; 10-30-2009, 08:47 AM.

                  Comment


                    #10
                    Argo1, thanks for clarifying - unfortunately this is expected as the Internal Order Handling Rules would still trigger as you mix the Set() and Exit() methods.

                    Comment


                      #11
                      Yes, but it's mix between different positions, not the same. Sad, that's unsupported. And there is no workaround besides that one described by me?

                      Comment


                        #12
                        You could try separating those signals in two different strategies...

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by argusthome, Yesterday, 10:06 AM
                        0 responses
                        22 views
                        0 likes
                        Last Post argusthome  
                        Started by NabilKhattabi, 03-06-2026, 11:18 AM
                        0 responses
                        19 views
                        0 likes
                        Last Post NabilKhattabi  
                        Started by Deep42, 03-06-2026, 12:28 AM
                        0 responses
                        14 views
                        0 likes
                        Last Post Deep42
                        by Deep42
                         
                        Started by TheRealMorford, 03-05-2026, 06:15 PM
                        0 responses
                        10 views
                        0 likes
                        Last Post TheRealMorford  
                        Started by Mindset, 02-28-2026, 06:16 AM
                        0 responses
                        41 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Working...
                        X