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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      657 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      373 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
      579 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X