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 Mindset, 04-21-2026, 06:46 AM
      0 responses
      57 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      78 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      41 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      101 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      61 views
      0 likes
      Last Post PaulMohn  
      Working...
      X