Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with OnExecution and TraceOrders

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

    Problem with OnExecution and TraceOrders

    I'm trying to debug a missed SetTrailStop() exit using TraceOrders. I have SetTrailStop() placed inside the OnExecution() method. None of the trailing stops or amended trailing stops are showing up in the Output Window but all of the PlaceOrder() methods are appearing correctly.

    Is there some reason why SetTrailStop() orders wouldn't show up in a log if placed inside OnExecution()? What else can I do to get TraceOrders to work with OnExecution()? If TraceOrders won't work how would you suggest that I debug the missing trailing stop that I'm trying to fix? The code can be seen in the attached .jpg file.

    FWIW, I was advised by someone at NT to put the stops in OnExecution to assure that trailing stops were placed upon confirmation of an entry fill.
    Attached Files

    #2
    bluelou, if you are placing stops inside OnExecution(), you will have to work with IOrders, like this:
    Code:
    IOrder stopOrder1 = ExitLongStop(...);
    OnExecution() and the other order update methods do not know about bars, so there is no context for setting a trail stop inside of those methods.

    You could work around this by setting some bool flag inside OnExecution() and then reading that flag inside OnBarUpdate() to set your trailing stop as soon as the execution occurs. If you set CalculateOnBarClose = false, then the stop would be set as soon as the next tick comes in.
    Code:
    bool setStop = false;
    OnExecution(IExecution ex)
    {
       if (ex is execution you're looking for)
       {
          setStop = true;
       }
    }
    OnBarUpdate()
    {
       if (setStop)
       {
           setStop = false;
           SetTrailStop(...);
       }
    }
    AustinNinjaTrader Customer Service

    Comment


      #3
      Austin,
      I'll try your suggestion but I'd like to know what you'd suggest as alternatives to OnExecution() when using SetTrailStop(). Originally, I had SetTrailStop() in OnBarUpdate() but the trailing stops were being set incorrectly and, on occasion, were being set before the entry occurred, causing another set of errors. My key concern is that I want confirmation of a fill before SetTrailStop() is called.

      Can I put SetTrailStop() in OnOrderUpdate()? Would that yield better results? What would you recommend?

      Thx,
      Lou

      Comment


        #4
        Lou, my previous statements may not have been 100% accurate, so I will have someone get back to you on Monday. Until then, the 100% guaranteed method would be to use IOrders, which you would have full control over. This would also mean you'd have to adjust the stop price every time the price was updated because it would not be automatic.
        AustinNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Austin View Post
          Lou, my previous statements may not have been 100% accurate, so I will have someone get back to you on Monday. Until then, the 100% guaranteed method would be to use IOrders, which you would have full control over. This would also mean you'd have to adjust the stop price every time the price was updated because it would not be automatic.
          Austin,
          Just to be clear is it correct that you are saying that I should not follow the code example in your previous post and instead use IOrders and that someone will get back to me on Monday on how this might be done using OnExecuction()?

          -Lou

          Comment


            #6
            Originally posted by NinjaTrader_Austin View Post
            OnExecution() and the other order update methods do not know about bars, so there is no context for setting a trail stop inside of those methods.
            This is the bit I am not completely sure about, but both other methods I outlined (IOrders and a bool flag) could work.
            AustinNinjaTrader Customer Service

            Comment


              #7
              Okay, I get it. Thx for clarifying.

              Comment


                #8
                Lou, the Set() methods would not offer native access via the IOrder objects, hence their tracking can be a bit more invoved, we have a reference sample though that would show how to start doing this - http://www.ninjatrader.com/support/f...ead.php?t=5790

                Coding your own custom trailstop amending tick by tick using the Exit() methods would be perhaps a more direct way and offering you also more control as Austin noted previously.
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Bertrand View Post
                  Lou, the Set() methods would not offer native access via the IOrder objects, hence their tracking can be a bit more invoved, we have a reference sample though that would show how to start doing this - http://www.ninjatrader.com/support/f...ead.php?t=5790

                  Coding your own custom trailstop amending tick by tick using the Exit() methods would be perhaps a more direct way and offering you also more control as Austin noted previously.
                  Bertrand,
                  I've tried a custom trailing stop using the Exit() methods as you've suggested but then I call the Exit() methods into OnExecution(). This has resulted in missed trailing stops just as using SetTrailStop() has.

                  Is it your recommendation that I use the Exit() methods only within the OnOrderUpdate() event handler and not OnExecution()? BTW, I'm not trying to do anything exotic, I just don't want errors with my trailing stops and that's been the experience so far.

                  Comment


                    #10
                    Lou, the Exit() methods IOrder returns can be used in both the OnOrderUpdate() as well as the OnExecution().

                    The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()


                    What kind of issue are you seeing with your trailstops?

                    Could it be you run into the Internal Order Handling Rules?

                    This would be seen if you run your strategy with the TraceOrders turned on in your Strategy Initialize().
                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      Yes, the error that I'm seeing, using TraceOrders, is due to Internal Order Handling Rules. The message reads that an Exit() method has been ignored. I'm still trying to figure out why the Exit() was ignored.

                      I'll let you know what I find. But, if you have any suggestions I'd like to hear them.

                      Thx,
                      Lou

                      Comment


                        #12
                        Thanks for clarifying, please see the bottom section of this link for the scenarios when this would be the case - http://www.ninjatrader-support.com/H...verview36.html
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          I'll take a closer look at the link to the help guide. I noticed that you sent me an NT6.5 help guide link. Any particular reason for that? I'm using NT7.

                          Comment


                            #14
                            No particular reason, the related content is the same, in NT7's help this is found under the 'managed order submission approach' - http://www.ninjatrader.com/support/h...d_approach.htm
                            BertrandNinjaTrader Customer Service

                            Comment


                              #15
                              ok, thx. I'll check it out.

                              Comment

                              Latest Posts

                              Collapse

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