• 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.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Sleeping Indicators

Collapse
X
  • 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, 08:06 AM.

    #2
    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() ?

    Comment


      #3
      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, 08:32 AM.
      JimNinjaTrader Customer Service

      Comment


        #4
        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, 08:38 AM.

        Comment


          #5
          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)

          https://ninjatrader.com/support/help...tm#Performance

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

          Comment


            #6
            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.

            Comment


              #7
              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

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Johnny Santiago, Today, 04:50 AM
              1 response
              6 views
              0 likes
              Last Post NinjaTrader_ChrisSch  
              Started by rickyblah12, Yesterday, 08:17 PM
              1 response
              12 views
              0 likes
              Last Post NinjaTrader_PaulH  
              Started by jamarc, Today, 02:30 AM
              0 responses
              4 views
              0 likes
              Last Post jamarc
              by jamarc
               
              Started by mrlucky1x, Yesterday, 08:07 PM
              1 response
              6 views
              0 likes
              Last Post NinjaTrader_PaulH  
              Started by uday12, Yesterday, 07:21 PM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_Jim  
              Working...
              X