Announcement

Collapse
No announcement yet.

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.

    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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      650 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      370 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      109 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      574 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      577 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X