Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator lifecycle

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

    Indicator lifecycle

    Hello!

    The idea here is to make an indicator inactive after a certain period of time. Let's imagine that I want the indicator to be inactive after one day up from now.
    I have the following code:
    HTML Code:
     protected override void OnStateChange()
    {
        else if (State == State.Terminated)
          {
              if(ToDay(Time[0]) > 20220329)
               {
                   return;
               }
          }
    }
    In this example, the indicator was not supposed to be working after 2022 03 29, but after ploting the indicator on the chart I can have the indicator working after that date.

    What could be wrong in my code?
    I would really appreciate any help.

    Many thanks in advance.
    Last edited by Stanfillirenfro; 03-30-2022, 05:24 PM.

    #2
    Hello Stanfillirenfro,

    Put the return condition in OnBarUpdate.

    OnStateChange State.Terminated is run when script is being removed or reloaded.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello SchelseaB!

      Many many many thanks!

      It works.

      Thanks again.

      Comment

      Latest Posts

      Collapse

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