Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Closing a Position from within OnTermination()

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

    #16
    Originally posted by cmt_Robert View Post
    Thanks Koganam.

    Is there a better way to accomplish what I am trying to accomplish? If not then this seems like (at least) a deficiency or (at worst) a bug in the way NinjaTrader works.
    Well, you might call it a deficiency: that would be probably a matter of opinion. The long and short is that there will probably have to be a design change to accommodate how you want to use OnTermination(). Basically to execute and report any orders before starting the termination proper as done currently.

    I would not call it a bug, as it looks like a reasonable design decision to run nothing in the Termination event handler. I am even surprised that the order went through.

    That having been said, I see your point entirely. Maybe you should make a feature request. Such niceties are some of the things that designers sometimes overlook because they are not very obvious at design spec time.

    Comment


      #17
      You make very valid points. Thank you again!

      I view it as a deficiency because it prevented me from doing that which I was seeking to do, and forced me to kludge together an inelegant solution instead. I abhor inelegant solutions.

      How have you approached this, koganam? I can't believe that I'm alone in wanting to protect myself in the event of a manual or unplanned strategy termination.

      And to those of the NinjaTrader_ persuasion listening in, I would indeed make the following request for a feature:

      Please provide a method which is called immediately and ONLY before OnTermination for which other methods (such as OnExecution, OnPositionUpdate and OnOrderUpdate) are still visible. This would be useful for ensuring that open positions can be gracefully exited prior to termination, with full event-driven accounting still being available.

      Comment


        #18
        Originally posted by cmt_Robert View Post
        You make very valid points. Thank you again!

        I view it as a deficiency because it prevented me from doing that which I was seeking to do, and forced me to kludge together an inelegant solution instead. I abhor inelegant solutions.

        How have you approached this, koganam? I can't believe that I'm alone in wanting to protect myself in the event of a manual or unplanned strategy termination.

        And to those of the NinjaTrader_ persuasion listening in, I would indeed make the following request for a feature:

        Please provide a method which is called immediately and ONLY before OnTermination for which other methods (such as OnExecution, OnPositionUpdate and OnOrderUpdate) are still visible. This would be useful for ensuring that open positions can be gracefully exited prior to termination, with full event-driven accounting still being available.
        I use the very inelegant kludge that I already spoke about. I write any information that I want to an external file using a StreamWriter just before I dispose of it in OnTermination(). That means that most of the time nothing gets written. However, on an abnormal termination, if OnTermination() gets called, the situations that I want to trap are written out to file.

        Regardless, I never leave automated strategies running and walk away for more than the time to get a snack or use the restroom. Automated trading at the retail trading level is NEVER a "set it and forget it" proposition. Heck even a big trading firm (Knight Capital) blew up because its automated traders went keplui. Just think how much resources they had in the IT department, and automated trading still made them broke.

        Of course, if all my orders are sitting at the exchange, I might have a different opinion, but too many brokers just do not have the correct setup to have all orders at the exchange, and NT is often simulating OCO for my Exit orders. To avoid problems, even though I know there are some brokers that can have orders sitting on the exchange, I just assume that that is never the case, and that all OCO is NT simulated. Better safe than sorry.
        Last edited by koganam; 05-18-2014, 11:31 AM. Reason: Corrected spelling.

        Comment

        Latest Posts

        Collapse

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