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

Distinguish in "State.Terminated" whether the indicator will be reloaded or removed

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

    Distinguish in "State.Terminated" whether the indicator will be reloaded or removed

    Hey guys,
    I'm designing some features for my indicator and I came across this question:
    Is it possible to distinguish in "State.Terminated" whether the indicator will be reloaded or removed?
    I want to do different things when the indicator is reloaded and when it is removed.

    Thanks.​

    #2
    Hello rafaelcoisa,

    Thank you for your post.

    Unfortunately no, State.Terminated is only called once when the object terminates (not reloads). You can specify in State.Terminated to do things like remove custom resources once the indicator is removed.





    Please let us know if you have any further questions.
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      ​Hey NinjaTrader_Gaby

      By "reload" I mean all actions that trigger the "State.Terminated" but do not remove the indicator, such as changing the chart time-frame, changing the chart instrument, adding another indicator, reload ninjascript (F5 hotkey), etc.
      Just to make sure the answer to my question is "no", I'll rephrase the question:
      Is there a way to distinguish whether “State.Terminated” was triggered because the indicator will be removed or by some other action that triggers “State.Terminated”?​

      Comment


        #4
        Hello rafaelcoisa,

        Thank you for your clarifying.

        No, unfortunately I am not aware of any supported or documented way to detect why State.Terminated was triggered.

        Please let me know if you have any further questions.
        Gaby V.NinjaTrader Customer Service

        Comment


          #5
          NinjaTrader_Gaby

          Another thing, when I add or remove an indicator, is this “add” or “remove” done in a collection?
          I was thinking that if the "add" or "remove" happens on a collection and the "remove" happens before the "State.Terminated" trigger on my indicator, I could somehow detect if the indicator will be removed before that happens and thus put two different logics in "State.Terminated", one for removing and another for "reloading".

          Comment


            #6
            Hello rafaelcoisa,

            No, this is not done in a collection. I recommend reviewing the Help Guide page below on the NinjaScript Lifecycle to understand what happens when you are adding an indicator to a chart:



            Please let me know if you have any further questions.
            Gaby V.NinjaTrader Customer Service

            Comment


              #7
              NinjaTrader_Gaby

              When I add an indicator to a chart, is there no collection involved?
              I thought ChartControl had a collection for this. No?​

              Comment


                #8
                Hello,

                Yes, there is a collection in the ChartControl however unless I am misunderstanding, you are trying to detect if the indicator has been removed from within that same indicator which wouldn't be possible. The "remove" happens when the script reaches State.Terminated - you wouldn't be able to detect a "remove" before reaching State.Terminated.



                Once the script has been removed because it has reached State.Terminated, then the collection would be updated since it would no longer be currently configured on the chart.

                You could be able to keep track of currently configured indicators on a chart from a separate indicator from OnRender().
                Gaby V.NinjaTrader Customer Service

                Comment


                  #9
                  NinjaTrader_Gaby

                  "to detect if the indicator has been removed from within that same indicator". Yes, that's what I was thinking about doing.
                  And, what about to "keep track of currently configured indicators on a chart from a separate indicator", is there an sample for that?
                  I know how to print the names of the currently configured indicators on a chart, but I still don't know how to keep track of them.

                  I saw how to do something similar with drawingtools here:
                  Hello, I have looked on the forums and references for this feature, it seems it's not available by default. I wonder if there's any third-party library I could use, or maybe there has been an update for it that I'm not aware of. I would like events for: DrawingTool Created DrawingTool Deleted DrawingTool Properties Changed

                  Comment


                    #10
                    Hello,

                    Please see the attached sample script using the chart control Indicators collection.

                    Attached Files
                    Gaby V.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by lightsun47, Today, 03:51 PM
                    0 responses
                    2 views
                    0 likes
                    Last Post lightsun47  
                    Started by 00nevest, Today, 02:27 PM
                    1 response
                    8 views
                    0 likes
                    Last Post 00nevest  
                    Started by futtrader, 04-21-2024, 01:50 AM
                    4 responses
                    42 views
                    0 likes
                    Last Post futtrader  
                    Started by Option Whisperer, Today, 09:55 AM
                    1 response
                    13 views
                    0 likes
                    Last Post bltdavid  
                    Started by port119, Today, 02:43 PM
                    0 responses
                    8 views
                    0 likes
                    Last Post port119
                    by port119
                     
                    Working...
                    X