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

State.Terminated

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

    State.Terminated

    I have coded the following:
    if (State == State.Terminated)
    {Print("ProgramEnd");}

    The result is 4x a printed statement: ProgramEnd.

    Why do I get more than 1 printed statement of "ProgramEnd"?
    Are there more occasions of State.Terminated in one Strategy Analyzer run?

    #2
    Hello PaulZ,

    Thank you for your post.

    The Termianted State would be called for any strategy and any strategy instance. This is explained in further detail at the following link: http://ninjatrader.com/support/helpG...fecycle_of.htm

    Please let me know if you have any questions.

    Comment


      #3
      I find the explanation very confusing and don't understand why NT8 is better than NT7 on this.

      I want to perform a calculation on my trades (NT8: SystemPerformance.AllTrades) once at the completion of a single strategy.
      With NT7 I used OnTermination() and this worked perfectly OK.
      With NT8 I use "if (State == State.Terminated)" and this resuts in 4 calculations. I do not understand why this is happening and I do not want 4 calculations but a single calculation, like I had in NT7.
      Can you please help?

      Comment


        #4
        Hello PaulZ,

        Thank you for your response.

        You can use a bool in NinjaTrader 8 to determine when an instance is actually ran over the data. The example below if taken from the lower section of the Help Guide article "Understanding the life cycle of your NinjaScript objects".
        Code:
        // custom flag to help time termination logic
        private bool toolBarNeedsReset = false;
         
        protected override void OnStateChange()
        {
          if (State == State.SetDefaults)
          {
            Name = "State lifetime indicator";
          }
          else if (State == State.Historical)
          {
            // before indicator starts historical processing
            // add a custom tool bar using a custom method
            AddToolBarButton(); // this is a pseudo-method for example purposes
            toolBarNeedsReset = true; // use a flag to track this logic was executed
          }
         
          else if (State == State.Terminated)
          {
            // here we intend to remove the custom tool bar when the indicator shuts down
            if (toolBarNeedsReset) // flag is only true after actually added
                RemoveToolBarButton();
          }
        }
        Reference: http://ninjatrader.com/support/helpG...fecycle_of.htm

        State.Terminated is included for each object's instance to assist in cleaning up resources. This was not present in prior versions of the NinjaTrader platform.

        Please let me know if you have any questions.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        4 views
        0 likes
        Last Post Javierw.ok  
        Started by timmbbo, Today, 08:59 AM
        2 responses
        10 views
        0 likes
        Last Post bltdavid  
        Started by alifarahani, Today, 09:40 AM
        6 responses
        40 views
        0 likes
        Last Post alifarahani  
        Started by Waxavi, Today, 02:10 AM
        1 response
        18 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by Kaledus, Today, 01:29 PM
        5 responses
        15 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X