NexusFi: Find Your Edge


Home Menu

 





is Sleep(0) ok within an indicator?


Discussion in NinjaTrader

Updated
    1. trending_up 2,249 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
ycomp
Europe-ish
 
Posts: 177 since Sep 2013
Thanks Given: 12
Thanks Received: 60

Is it ok to use Thread.Sleep(0) in OnBarUpdate() of an Indicator ?

I ask because the indicator I was using had a lot of plots and this seems to be the reason it would grind NT8 to a halt so that it took several seconds between clicking on a tab to change to that chart... or for a dialog like Data series to pop up.

I added it, so far so good- very responsive NT8 UI and no problems I can see.. but I'm just wondering if anyone can forsee any problems here.. I'm not a C# or NinjaScript expert.


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
My Rant with AMP Futures
Trading Reviews and Vendors
requesting .nrd replay files from 2026 spy and qqq
The Elite Circle
Building a free browser DOM/SMC simulator - need some ad …
Platforms and Indicators
What we know about Binances $6.3bn hack - BBC News
Cryptocurrency
AI for Traders — Agents, Memory, Tools & Real-Worl …
Elite Quantitative GenAI/LLM
 
  #3 (permalink)
 
sam028's Avatar
 sam028 
Site Administrator
 
Posts: 3,779 since Jun 2009
Thanks Given: 3,840
Thanks Received: 4,709



ycomp View Post
Is it ok to use Thread.Sleep(0) in OnBarUpdate() of an Indicator ?

I ask because the indicator I was using had a lot of plots and this seems to be the reason it would grind NT8 to a halt so that it took several seconds between clicking on a tab to change to that chart... or for a dialog like Data series to pop up.

I added it, so far so good- very responsive NT8 UI and no problems I can see.. but I'm just wondering if anyone can forsee any problems here.. I'm not a C# or NinjaScript expert.

A sleep for 0 millisecond will do nothing. Using a value > 0 will only delay the moment when the buggy/heavy computing stuff will be done, so not useful either. Also it will only delay one thread, not the GUI thread.
Globally a bad idea.


Success requires no deodorant! (Sun Tzu)
Reply With Quote
Thanked by:
  #4 (permalink)
ycomp
Europe-ish
 
Posts: 177 since Sep 2013
Thanks Given: 12
Thanks Received: 60


sam028 View Post
A sleep for 0 millisecond will do nothing. Using a value > 0 will only delay the moment when the buggy/heavy computing stuff will be done, so not useful either. Also it will only delay one thread, not the GUI thread.
Globally a bad idea.

well it seems to have eliminated my responsiveness problems. And cpu usage also drops for ninjatrader (I have several charts open)

Sleep(0) does something, I have used it in other languages in many situations to reduce cpu usage and delays when you're in a loop... it is similar to Yield() but with differences... https://stackoverflow.com/a/16584612/270143

as you can imagine, you don't want to have to wait several seconds or longer (could be 5 or 10 seconds or more sometimes) every time you switch to another chart tab or open a dialog.

I think this problem is not common because most indicators only use a handful of plots.


Reply With Quote




Last Updated on March 18, 2019


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts