NexusFi: Find Your Edge


Home Menu

 





is Sleep(0) ok within an indicator?


Discussion in NinjaTrader

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




 
Search this Thread

is Sleep(0) ok within an indicator?

  #1 (permalink)
ycomp
Europe-ish
 
Posts: 177 since Sep 2013
Thanks Given: 12
Thanks Received: 58

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?
Exit Strategy
NinjaTrader
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
ZombieSqueeze
Platforms and Indicators
Increase in trading performance by 75%
The Elite Circle
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
34 thanks
Tao te Trade: way of the WLD
24 thanks
GFIs1 1 DAX trade per day journal
16 thanks
Vinny E-Mini & Algobox Review TRADE ROOM
13 thanks
My NQ Trading Journal
12 thanks
  #3 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629



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)
Follow me on Twitter Reply With Quote
Thanked by:
  #4 (permalink)
ycomp
Europe-ish
 
Posts: 177 since Sep 2013
Thanks Given: 12
Thanks Received: 58


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


© 2024 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 - Privacy Policy - Downloads - Top
no new posts