No announcement yet.

Partner 728x90


Detecting when a chart is done loading.

  • Filter
  • Time
  • Show
Clear All
new posts

    Detecting when a chart is done loading.

    Is there a way to detect when a chart and all its indicators are done processing historical data and have transitioned to real time?

    Hello ntbone, thanks for your question.

    Unfortunately not. The addon framework can not peek into each individual chart in the workspace to know when it has finished loading. One solution could be to have an indicator update a .txt file and write the state information to the .txt file, then the addon can read the .txt file to know what state the indicator is in.

    Please let me know if I can assist any further.
    Chris L.NinjaTrader Customer Service


      With that approach, how would I know all the indicators have also finished processing? The indicator that creates the text file could be before some other indicator that hasn't finished. Are indicators processed in a guaranteed order?


        Hello ntbone, thanks for your reply.

        You would not be able to know about the other indicators unless you programmed the same thing in all indicators. Indicators will load in the order they were added to the chart. What is the reason you needed to do this? I could possibly provide an alternative solution.

        Best regards.
        Chris L.NinjaTrader Customer Service


          In the indicator configuration dialog the order there is the order processed?

          I want an addon to scroll through some instruments automatically changing them. Using linked instrument functionality it can change the charts of linked windows. However I don't want it to change them unless they have all finished loading.


            Hello ntbone,

            In the indicator configuration dialog the order there is the order processed?
            This is what I noticed in my tests. There is no documentation for how that works exactly, so it might not be the same for all cases and will need to be tested throughout with all different types of indicators ( e.g. OnBarClose vs OnEachTick vs single series vs multiple series scripts).

            Unfortunately, there is no supported or documented way for an addon to easily peek into all charts of a workspace. Regrettably, I will not be able to suggest any solution here.

            Please let me know if I can be of any further assistance.

            Chris L.NinjaTrader Customer Service


              Aren't all the indicators on a chart brought through the various
              state changes via OnStateChange together en masse, on a
              per state basis?

              I mean, wouldn't NT8 loop through all indicators for the single state,
              such as "DataLoaded", one by one, before sending any indicator
              the state change to next state of "Historical"?

              ... and then loop through all indicators sending "Historical" before
              sending the next state "Transition"?

              ... and then loop through all indicators sending "Transition" before
              sending the next state "RealTime"?

              So, in state "RealTime", it seems to me, the OP's question becomes,
              have all other indicators completed their transition to state "RealTime"?

              My quick idea (not tested) out of the box is this:

              protected override void OnStateChange()
                  if (State == State.RealTime)
                      TriggerCustomEvent(OnRealTimeComplete, null);
              private void OnRealTimeComplete(object obj)
                  ChartObjectCollection<IndicatorRenderBase> indCollection = ChartControl.Indicators;
                  int stateCount = 0;
                  foreach (IndicatorRenderBase ind in indCollection)
                      if (ind.State >= State.RealTime)
                  if (stateCount != indCollection.Count)
                      // keep checking
                      TriggerCustomEvent(OnRealTimeComplete, obj);
                  Print("All Indicators are at state RealTime or later");
              Could this idea (repeatedly calling same trigger from itself) work?

              It all depends if TriggerCustomEvent schedules the custom call into
              the queue of events (ie, enqueues our delegate into call stream of
              pending callbacks, such as OnBarUpdate, OnStateChange, etc) or
              immediately sets up the CurrentBar context and calls the delegate
              right then and there?

              Unfortunately, the immediate case would probably cause an endless loop.

              the hope is that our custom event would be scheduled. Which means,
              while it is waiting to be called, NT8 does other work, such as sending
              those State changes to other indicators, so that when our custom event
              is called again (perhaps multiple times), it will eventually see the State
              changes made to the other indicators, until at some point, all states
              are State.RealTime or greater.

              The benefit of this approach might also depend on multi-threading
              considerations, but I don't know. Obviously, this needs testing. I don't
              know precisely how TriggerCustomEvent interacts with NT8's event-driven
              programming model. I would hope it inserts our custom event at the back
              of the normal event queue ... can some one in Support comment on this?

              [Also, an "event" in NT8's even-driven programming parlance is really, I
              presume, just a call to any of the overridden callbacks prefixed with "On",
              such as OnBarUpdate, OnMarketDepth, OnStateChange, etc etc]

              The idea has some merit, I think.
              But, can't test it right now ... not at NT8 trading computer.

              Last edited by bltdavid; 02-19-2021, 05:46 PM.


                Interesting idea. If I create an indicator that uses it I might be able to have it signal my addon so it knows everything is done and it can move on. This indicator would need to be added to each chart that I am interested in checking.

                I am guessing that each indicator goes through each state one at a time as well based on behavior of the app. I haven't verified it though.


                  More ideas here and here.


                  Latest Posts


                  Topics Statistics Last Post
                  Started by hayleeabb, Today, 04:21 PM
                  1 response
                  Last Post NinjaTrader_ShawnB  
                  Started by mg.watts, Today, 03:17 PM
                  1 response
                  Last Post NinjaTrader_ChrisL  
                  Started by JTizz, Today, 01:20 PM
                  1 response
                  Last Post NinjaTrader_Jesse  
                  Started by omermirza, Today, 12:39 PM
                  2 responses
                  Last Post omermirza  
                  Started by mballagan, Today, 01:02 PM
                  1 response
                  Last Post NinjaTrader_Kate