• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.


No announcement yet.

Partner 728x90


Need insight on this error...

  • Filter
  • Time
  • Show
Clear All
new posts

    Need insight on this error...

    Can anyone provide an explanation of what causes this error:

    Error on calling 'EventHandlerMarketData' method: More than 100 subsequent user events

    Hello Gary,

    Thank you for your post.

    This essentially means you need to debug the script.

    The user events message is a safeguard for NS strategies to limit the number of potential user events per bar, so before control from the event queue is given back to NT's core processing, that number could be increased, but our suggested approach would be first understanding why this high a number of custom events would be thrown for your code.
    Patrick H.NinjaTrader Customer Service


      more info needed

      Please explain what you mean 'user events'.
      Do you mean the user watching the chart?
      Or do you mean user as in programmer and therefore events generated from my script?

      If it is the later, can you give an example of what would qualify as one of these events?
      Would a call to 'ForceRefresh()' qualify?



        Hello GaryAlbers,

        Thank you for your patience.

        This would be the events in the script. And this could be any item including ForceRefresh().
        Patrick H.NinjaTrader Customer Service


          This may not be what you need, but you can try adding this to Initialize,

          // increase depth of event queue
          MaxProcessedEvents = 1000;


            Hello all,

            I know this is kind of an old thread but I am facing some relatively similarly situation with NT7, only that I am using a timer / custom event e.g.

            protected override void OnStartUp()
            posSyncTimer.Tick += new EventHandler(TimerEventProcessor);
            posSyncTimer.Interval = 500;

            private void TimerEventProcessor(Object obj, EventArgs args)
            TriggerCustomEvent(doStuff, 0, posSyncTimer.Interval);

            I was wondering, instead of setting an arbitrary MaxProcessedEvents, is there a way to catch and handle these errors? Mine is something like:

            **NT** Error on triggering custom event for strategy [...]: More than 100 subsequent user events

            I've tried to override OnStop, OnTermination, OnLifetimeStatus, On[almost anything] and try-catch the error but is seems the error still gets thrown... any thoughts?

            Thanks in advance!


              I am attaching the code and output for reference - I just don't understand how this simple timer code is integrated into the NT7 event processing system, and from where does that exception get thrown:

              **NT** Error on triggering custom event for strategy 'MyStrategy/a79a71f1ac0048fcb54e1c4408634ab0': More than 10 subsequent user events

              .. any thoughts


              Attached Files


                Here is my THEORY of what is happening in your strategy:
                - The Ninja engine that is running your strategy has logic to guard against various kinds of run-away client code, in this case 'More than 100 subsequent user events'.
                - your timer is firing every 500 millis and each time it fires, it tells .NET to generate an event which will call ProcessNewData.
                - I suspect your strategy is running on a chart that has a slow enough frequency between calls to OnBarUpdate that the number of events exceeded 100 (or 10 in your sample code since you set MaxProcessedEvents = 10).

                One solution is to have the method: TimerEventProcessor directly call: _processNewDataImpl instead of generating an event to call it.

                WARNING: Be thread aware!
                1) When OnBarUpdate is called by Ninja, all data is up to date and you can access data series objects like Close using standard notation: Close[0].
                HOWEVER, any code that is called from a different thread than OnBarUpdate requires that your code use Close.Get(myCurrentBarBasedIndex).
                2) If your code updates any GUI widgets on the chart/window then you have to call the correct .NET method to place that call on the GUI thread.

                The above is just a guess



                  Thanks, Gary - I tend to agree with you, for the most part, still I'm a bit reluctant to the idea of calling directly the "impl" method (I'm afraid it might cause more stability issues than the ones which the framework is trying to protect us against by enforcing the "max_events" limit).

                  I think in the end I'll go with an adjusted value (probably significantly larger) of the above mentioned property, after doing more performance-related testing.


                    Hello smf2005,

                    GaryAlbers is correct in that the error is caused by a NinjaTrader safeguard to prevent too many events from being triggered and causing performance issues such as lockups. I personally would not recommend calling _processNewDataImpl and bypassing this safeguard. Instead, I would recommend reworking the script to decrease the number of events being triggered per bar or increasing the MaxProcessedEvents (keep in mind this safeguard is to prevent performance issues and lock ups).

                    The timer itself will be running in a new different thread than the thread of the script's data driven methods. Each time you are triggering events with method calls to NinjaScript items this will be queued and run in the scripts thread. If too many items are in the queue, the CPU could be overloaded and this safeguard in the script throws an error.

                    I am not aware of an override to catch when this error is being thrown.
                    Last edited by NinjaTrader_ChelseaB; 05-28-2020, 10:51 AM.
                    Chelsea B.NinjaTrader Customer Service


                      Thank you, Chelsea, for the detailed explanation.

                      Now if you ask me, this safeguard may sound a bit over-protective since there may be strategies which simply do not have anything to do with current bar (like for generating custom reports, or monitor various things on the local disk). But of course, I understand this is a platform architecture decision, so one would need to play along with the way its currently implemented.

                      It would be interesting though if you could provide us bit more info about this property since it doesn't seem to be described anywhere in the official documentation:
                      - the default value is 100, ok, but you say this should be considered in relation with the current bar... disregarding of bar frequency? So is this to be taken like "max 100 events per 1 min bar" and also "max 100 events per 1 week bar"?
                      - does the property have any max value which can be set (apart from Integer.MaxValue) ?
                      - how about minimum value, can it be set e.g. to 0? (would that disable the safeguard or... )?

                      Thank you.


                        Hello Sorin,

                        NinjaTrader was not actually designed for this undocumented code of using timers. It's not documented because this involves starting new threads which officially is not supported by NinjaTrader. (So use at your own risk)

                        This property and safeguard exists because NinjaTrader is trying to mitigate the performance issues caused by scripts using undocumented code and creating new threads that spam the NinjaScript thread with events by calling too many stacked NinjaScript methods and lockup the application that the user base are importing onto their machines from 3rd parties.

                        If a script is getting this error, generally this means this is not a high performance script and will cause issues.
                        You can choose to set the MaxProcessedEvents to a higher number.


                        Setting to 0 would trigger the error on the first event.
                        Chelsea B.NinjaTrader Customer Service


                          Hello Chelsea,

                          I understand, and I agree with you - all the context is much clear now.
                          Thank you once again!

                          Best regards,


                          Latest Posts


                          Topics Statistics Last Post
                          Started by pjsmith, Today, 01:13 AM
                          0 responses
                          Last Post pjsmith
                          by pjsmith
                          Started by yukashg, Yesterday, 09:56 PM
                          1 response
                          Last Post NinjaTrader_ChrisSch  
                          Started by cutzpr, Yesterday, 09:19 PM
                          1 response
                          Last Post NinjaTrader_ChrisSch  
                          Started by nestorjt23, Yesterday, 08:55 PM
                          3 responses
                          Last Post NinjaTrader_EricB  
                          Started by 7robert, Yesterday, 08:30 PM
                          1 response
                          Last Post 7robert
                          by 7robert