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

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)



          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 yertle, Yesterday, 08:38 AM
              7 responses
              28 views
              0 likes
              Last Post yertle
              by yertle
               
              Started by bmartz, 03-12-2024, 06:12 AM
              2 responses
              21 views
              0 likes
              Last Post bmartz
              by bmartz
               
              Started by funk10101, Today, 12:02 AM
              0 responses
              4 views
              0 likes
              Last Post funk10101  
              Started by gravdigaz6, Yesterday, 11:40 PM
              1 response
              8 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by MarianApalaghiei, Yesterday, 10:49 PM
              3 responses
              10 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Working...
              X