Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

How can I exit an Indicator

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

    How can I exit an Indicator

    Is there anyway to exit the processing of an indicator altogether in order to draw text on the pane? For example, if I make a license call to my server and the user is not licensed, I am trying something like this:

    Code:
    protected override void OnBarUpdate()
    {          
        if (!FancyLicensingBool)
        {                    
            Draw.TextFixed(this, "license-errors", "Not Licensed", TextPosition.Center, Brushes.Black,new SimpleFont("Arial", 16), Brushes.Black, Brushes.White, 100);             
            return;
        }
    }
    I have that in OnBarUpdate but it only returns one time and then OnBarUpdate is called again. Is there a way to call some sort of halt action instead of returning? Something that would leave the text in the pane?

    #2
    There is option to use {SetState(State.Finalized);} instead of return;

    There is also State.Terminated but I've found this does not exit indicator, it just starts it again in the same way using "return;" does. I don't think State.Finalzed is supported by NT support so I guess you use it at your own risk. Hopefully someone from NT will be able to explain there usage better.

    Comment


      #3
      Hello swooke,

      Thanks for your post.

      If you want to have the indicator draw on the chart, I would suggest setting a bool and then drawing on the chart like you have done. Aborting the indicator will cause the drawing objects to disappear.

      This would not be a supported approach so your mileage may vary, but you could try removing your indicator from the ChartControl.Indicators collection. I would not recommend trying this with indicators that use IsOverlay = false since removing from the Indicators collection will not remove the added panel.

      ChartControl.Indicators.Remove(this);

      You could combine this with throwing an exception so an error is noted in the Log tab of the Control Center.

      throw new Exception("Script terminated.");

      I'll leave the thread open for other community members that may have input using unsupported code.
      JimNinjaTrader Customer Service

      Comment


        #4
        Yeah, whatever happened to the NT7 method of using "Enabled = false;"? (for ex, see NT7's @Pivots.cs indicator)

        I mean, it would seem that the NT8 equivalent of "Enabled = false;" is what the OP is looking for.

        I also note that NT7 Strategy supported a Disable() method (which I assumed was a wrapper for that 'Enable' variable),
        does NT8 have an equivalent for that?

        I mean, one would think there should be a common universal "Disable()" like method in NT8 that would work
        similarly across all plugin types -- aka, Indicators, Strategies, and Addons ... does that exist? If not, why not?

        What is the correct/documented/supported way to disable your NT8 NinjaScript object?

        Comment


          #5
          Hello bltdavid,

          The Enabled property is not documented for NinjaTrader 7 and we have moved away from doing this in NinjaTrader 8. NinjaTrader 8 Pivots will draw text on the chart and log an error so the user is informed of what happened with the script.

          Disable() in NinjaTrader 7 is for strategies only and is replaced with CloseStrategy() in NinjaTrader 8.

          CloseStrategy() - https://ninjatrader.com/support/help...sestrategy.htm

          SetState(State.Terminated) would be our suggested way to terminate a script. Similar to what we see when setting Enabled to false in NinjaTrader 7, this will not remove the indicator from the chart.

          SetState - https://ninjatrader.com/support/help.../?setstate.htm

          We look forward to assisting.
          JimNinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Jim View Post
            Hello bltdavid,

            The Enabled property is not documented for NinjaTrader 7 and we have moved away from doing this in NinjaTrader 8. NinjaTrader 8 Pivots will draw text on the chart and log an error so the user is informed of what happened with the script.

            Disable() in NinjaTrader 7 is for strategies only and is replaced with CloseStrategy() in NinjaTrader 8.

            CloseStrategy() - https://ninjatrader.com/support/help...sestrategy.htm

            SetState(State.Terminated) would be our suggested way to terminate a script. Similar to what we see when setting Enabled to false in NinjaTrader 7, this will not remove the indicator from the chart.

            SetState - https://ninjatrader.com/support/help.../?setstate.htm

            We look forward to assisting.
            Hello Jim,

            When I use state terminated in an indicator script, the script will terminate once, then restart on the next bar so I cannot get it to actually terminate the script, it only terminates then start again. Am I missing something in how to use state terminated to ensure that it ends the script and it doesn;t start again or is this normal behaviour and only finalize actually stops the script from restarting?

            Comment


              #7
              Hello b16_aln,

              When you test with SetState(State.Terminated); are you calling this during historical processing or when the script is processing realtime data? When I test when State.Realtime is reached, the script no longer processes OnBarUpdate.

              Historical data is processed in a thread pool, so the same approach would not work here to set the state to State.Terminated when the script processes historical data. I would recommend using a return statement instead.

              If you have additional questions here, could you modify the test script I attached so we can look at a similar example?

              I look forward to assisting.
              Attached Files
              JimNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by merzo, 06-25-2023, 02:19 AM
              10 responses
              823 views
              1 like
              Last Post NinjaTrader_ChristopherJ  
              Started by frankthearm, Today, 09:08 AM
              5 responses
              15 views
              0 likes
              Last Post NinjaTrader_Clayton  
              Started by jeronymite, 04-12-2024, 04:26 PM
              3 responses
              43 views
              0 likes
              Last Post jeronymite  
              Started by yertle, Today, 08:38 AM
              5 responses
              16 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by adeelshahzad, Today, 03:54 AM
              3 responses
              19 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Working...
              X