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 charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      70 views
      0 likes
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      152 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      162 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 05-10-2026, 08:12 PM
      0 responses
      100 views
      0 likes
      Last Post CarlTrading  
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      288 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Working...
      X