Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetState(State.Terminated) does not terminate indicator immediately

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

    SetState(State.Terminated) does not terminate indicator immediately

    Hello,

    I use below code to terminate my indicator run. However, if I load 5 years of 1 hour chart, even though I call below code on Bar 10, logic still runs through 1000s more bars before it actually terminates, which is visible in output window since I do Print(CurrentBar);. Is there any way to terminate the run right after bar 10 and not go further?

    Thanks,
    redduke


    protected override void OnBarUpdate()
    {

    if(CurrentBar==10){

    SetState(State.Terminated);
    return;

    }

    Print(CurrentBar);

    }

    #2
    Hello RedDuke,

    Thank you for the post.

    For the time being you could add a condition following this to return if the state is terminated:
    Code:
    if(CurrentBar==10){
    
    SetState(State.Terminated);
    return;
    
    }
    if(State == State.Terminated) return;
    I will need to review this further to see what the expectation is surrounding setting terminated on an indicator during historical processing. The only notes I can find surrounding SetState relate to strategies. If I have further details I can provide here I will update the post.

    I look forward to being of further assistance.

    Comment


      #3
      Hi Jesse,

      It did not work. I still see 1000s of bars still being processed.

      Thanks

      Comment


        #4
        Hello RedDuke,

        I tried that on my end and see it working, is the State showing as Terminated for those bars in your test? You could use your own bool variable as well to do a similar task, set a bool to true and if that bool is true return.

        I look forward to being of further assistance.

        Comment


          #5
          Jesse,

          I did not check the status for these bars, but I want indictor to stop processing the bars all together. If I trigger termination logic on bar 10, how can I stop indicator processing all subsequent bars? This is what I can trying to achieve.

          Thanks

          Comment


            #6
            Hello RedDuke,

            Could you check the State in the test by using a print and provide that detail? I had observed the State was terminated for those bars if you are seeing something else I would like to know that.

            As mentioned I will be reviewing this further to see what the expectation would be surrounding the script being disabled at that point. For right now you can use a private variable to control this to proceed past the problem of allowing your logic to continue. Once I have more details here I will provide an update.

            I look forward to being of further assistance.

            Comment


              #7
              Here is what it looks like:

              0 Historical
              1 Historical
              2 Historical
              3 Historical
              4 Historical
              5 Historical
              6 Historical
              7 Historical
              8 Historical
              9 Historical
              10 Historical
              11 Terminated
              12 Terminated
              13 Terminated
              14 Terminated

              For all those 1000s of bars after I triggered termination, it becomes Terminated

              Thanks,
              redduke

              Comment


                #8
                Hello RedDuke,

                Thank you for checking that, this is the same result as I had observed.

                After further research I was able to find some internal notes surrounding SetState and terminated. This is not meant to be a kill switch but is only intended to set the state of the object. For realtime scripts that should stop it immediately but during historical processing we will see the result that we had observed here or that the state is terminated but OBU processes still. I am going to still forward this to development for further review to look into the Terminated state and allowing OBU to be called.

                You can use a condition in your logic to check if the state is terminated to return if you are going to be setting the state manually:

                if(State == State.Terminated) return;

                OnBarUpdate will still run but not past this point as long as the state is terminated.


                I look forward to being of further assistance.
                Last edited by NinjaTrader_Jesse; 12-18-2020, 03:35 PM.

                Comment


                  #9
                  if(State == State.Terminated) return; Is exactly what I am doing now. Any other help would be greatly appreciated.

                  Have a wonderful weekend!!!!

                  Regards,
                  redduke

                  Comment


                    #10
                    Hello RedDuke,

                    I just wanted to provide a quick update. I went ahead and reported this to development so they will review the situation further. If anything is changed surrounding this in a future version it will be under the number 14758 in the changelog. At this time there is no additional info I can relay on the issue.

                    For the time being you would need to just use a condition to return if the state is terminated like the condition you pasted. That could be used in any overrides that are used in the script which may be running still when you set the state manually.

                    I look forward to being of further assistance.

                    Comment


                      #11
                      Thanks a lot

                      Comment


                        #12
                        Hello RedDuke,

                        I just wanted to follow up, it looks like this was corrected and will be included in the next release in the 8.0.25.* update. Unfortunately I am not certain of a date on that, I just wanted to let you know that it should be corrected in the near future.



                        I look forward to being of further assistance.

                        Comment


                          #13
                          Hi Jesse,
                          Thanks for letting me know.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          648 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          369 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          108 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          572 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          574 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X