• 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


Sleeping Indicators

  • Filter
  • Time
  • Show
Clear All
new posts

    Sleeping Indicators

    are there any good places in an indicator to put a Sleep call to yield the thread so that other threads can get things done

    maybe? OnBarUpdate()

    I'm trying to figure out how to make the UI more responsive when a lot of indicators and tabs are being used. They are mostly custom indicators so it is possible to edit the source code.

    memory usage doesn't seem to be a problem (unless I were to have the data series look back a lot farther)

    for example to illustrate the problem, when I click on a tab for another chart in the window - it appear to do nothing then after several seconds or more will switch to that tab. Or if I right click choose data series, again it takes this long period of time for the dialog to appear
    Last edited by NinjaCustomer; 03-18-2019, 07:06 AM.

    ok, I added Thread.sleep(0) - wow it worked wonders.. in OnBarUpdate()...tabs and dialogs now very responsive.

    would there be any problems to using it in an indicator or in OnBarUpdate() ?


      Hello NinjaCustomer,

      Thanks for opening the thread.

      This sort of topic would exceed what we could offer for support. There are a lot of internal intricacies to NinjaTrader's multi threading that are not documented and we also do not have any practices that we suggest to halt a NinjaTrader thread to wait for other tasks to complete. You may find success in some areas, and you may incur threading issues in other cases.

      I'll leave this thread open ended for any Community members that have taken steps or have had success to start an asynchronous operation and have NinjaTrader wait until that operation completes.

      If there is another topic we can assist with, please do not hesitate to open a new thread.
      Last edited by NinjaTrader_Jim; 03-18-2019, 07:32 AM.
      JimNinjaTrader Customer Service


        just for clarification... I'm not starting any new threads.. it is just to sleep in C# you need to use Thread.Sleep();

        The problem is just that the indicator has a lot of plots and I think this is what results in the "slow down"

        So my understanding is that nobody knows if it is safe or not to call Thread.sleep() within OnBarUpdate() ? so far I haven't had any problems, was just wondering - I was thinking maybe this was a common issue to get slow downs when you have many plots or many indicators
        Last edited by NinjaCustomer; 03-18-2019, 07:38 AM.


          Hello NinjaCustomer,

          We note in our Help Guide to avoid calling Thread.Sleep() as it can lock the instrument thread. Since we do not offer any direction for halting these threads, any work that you would do here would be experimental.

          Below is a link to our Best practices page of the Help Guide where we advise not to use Thread.Sleep() and advise to use timers instead. (Please see the bottom of this section for Delaying logic for a particular time interval)


          Please let me know if there is anything else I can do to help.
          JimNinjaTrader Customer Service


            Hi Jim, how about Thread.Yield() then - would the logic that applies to not using Sleep() apply to Yield() as well?

            I'm not using Sleep() as a delay tactic, I use it simply to give some breathing room to other threads. So far I haven't run into any problems with Sleep(0) though, I think it might be fine.


              Hello NinjaCustomer,

              Although you would likely not encounter the same locking that is noted when using Thread.Sleep(), other issues could be caused if the thread is yielded prematurely. Community members are welcome to write in with their experiments and share their findings, but our Support Department will not be able to assist further with this topic.

              If there is another topic that we can assist with, please do not hesitate to open a new thread.
              JimNinjaTrader Customer Service


              Latest Posts


              Topics Statistics Last Post
              Started by mike09, 01-17-2020, 07:37 PM
              2 responses
              Last Post koganam
              by koganam
              Started by ChazJ, Today, 11:04 AM
              0 responses
              Last Post ChazJ
              by ChazJ
              Started by NT-Roland, 04-28-2018, 02:19 AM
              5 responses
              Last Post Balage0922  
              Started by tonynt, 04-16-2019, 06:27 AM
              13 responses
              Last Post fx.practic  
              Started by DTSSTS, Today, 09:53 AM
              0 responses
              Last Post DTSSTS
              by DTSSTS