Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

detect indicator removed or deactivated

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

    detect indicator removed or deactivated

    Hello,

    if I have installed an indicator (any),
    the following statuses are run through in the OnStateChange() method.

    OnStateChange() State: Terminated
    OnStateChange() State: Configure
    OnStateChange() State: DataLoaded
    OnStateChange() State: Historical
    OnStateChange() State: Transition
    OnStateChange() State: Realtime


    How can you tell if an indicator has been deactivated or removed from the chart?

    (I want to take certain actions when an indicator has been disabled or removed.)

    #2
    Hello 1001111,

    Thank you for the post.

    The State.Terminated would be how to tell that. Terminated can be called multiple times and for multiple different instances so depending on what you need to clean up you may need to also add logic to determine if the script actually started.

    Can you provide some detail about what you are trying to do when the script is disabled?

    A simple way to know the script started so you can know the next Terminated is actually when the script is being stopped would be to use a bool:




    Code:
    private bool myBool; 
    
    and then in OnStateChange: 
    
    if(State == State.Historical)
    {
        myBool = true; 
    } else if(State ==State.Terminated)
    {
        if(myBool == true)
        { 
             // we can safely assume the script was actually started because it hit state.historical
         }
    }

    I look forward to being of further assistance.

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post

      Can you provide some detail about what you are trying to do when the script is disabled?
      The indicator collects data during the term. But I have to delete it if it is deactivated or deleted.


      I'll try what you wrote. Thanks a lot

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      82 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      43 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      64 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      68 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      56 views
      0 likes
      Last Post CarlTrading  
      Working...
      X