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 called multiple times

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

    State.Terminated called multiple times

    Hello,

    My indicator logic is changing the
    Code:
    ChartControl.Properties.ChartBackground
    and I want to change it back to the initial value when the indicator is removed.

    I'm trying to make use of
    Code:
    State.Terminated
    but I encounter some issues.

    Firstly, the
    Code:
    State.Terminated
    is called multiple times (even after OK/Apply click). This is strange given the definition stated in the documentation.

    I am not bothered by the fact that ChartControl is null for some calls (it is not null for all calls).

    The problem is that
    Code:
    State.Terminated
    is happening multiple times and not just at the removing part.

    Is there another way to reset the
    Code:
    ChartControl.Properties.ChartBackground
    to the initial value?

    Thanks.

    #2
    Hello algunion,

    Welcome to the forums!

    NinjaScripts will be cloned twice when the Indicators menu is brought up. The first time is to list the indicators and the second time is to populate the properties grid with the properties of the selected indicator. State.SetDefault and State.Terminated are passed in these clone events.

    I may suggest making your changes to ChartControl.Properties.ChartBackground after State.DataLoaded has been reached, and then to keep track of the last state that was passed. This way, if OnStateChange() reaches State.Terminated after an Active state is reached, we know the State.Terminated is occurring on the removal of the indicator.

    As a loose example:
    Code:
    else if (State == State.Terminated)
    {
    	if(lastState == State.Realtime || lastState == State.Historical || lastState == State.DataLoaded)
    		Print("Removed.");
    }
    Publicly available information on the NinjaScript LifeCycle can be referenced here -


    Please let us know if we may be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      It works

      Thank you, Jim.

      This works. Just confirming in case someone else is searching the issue.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by FrazMann, Today, 11:21 AM
      0 responses
      1 view
      0 likes
      Last Post FrazMann  
      Started by geddyisodin, Yesterday, 05:20 AM
      8 responses
      51 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by cmtjoancolmenero, Yesterday, 03:58 PM
      10 responses
      36 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by DayTradingDEMON, Today, 09:28 AM
      4 responses
      24 views
      0 likes
      Last Post DayTradingDEMON  
      Started by George21, Today, 10:07 AM
      1 response
      18 views
      0 likes
      Last Post NinjaTrader_ChristopherJ  
      Working...
      X