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 SalmaTrader, 07-07-2026, 10:26 PM
      0 responses
      35 views
      0 likes
      Last Post SalmaTrader  
      Started by CarlTrading, 07-05-2026, 01:16 PM
      0 responses
      20 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 06-17-2026, 10:32 AM
      0 responses
      12 views
      0 likes
      Last Post CaptainJack  
      Started by kinfxhk, 06-17-2026, 04:15 AM
      0 responses
      18 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Started by kinfxhk, 06-17-2026, 04:06 AM
      0 responses
      20 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Working...
      X