View Full Version : Multithreaded indicator programming
supernatural
07-19-2010, 07:50 AM
Hello,
Does it make sense to do multithreaded programming in an NT7 indicator (for example in the hope of playing sounds without the charts lagging or to make use of multiple cores for intensive calculations), or will the code be executed anyway in a single thread/core?
Thanks
NinjaTrader_Austin
07-19-2010, 08:30 AM
supernatural, everything would be run in the same thread.
supernatural
07-19-2010, 10:00 AM
Please put it on a feature list for a future release as this is a must have in the age of multicore processors (and long existing multithreaded OSs).
NinjaTrader_Austin
07-19-2010, 10:05 AM
Thank you for the suggestion. I have forwarded it along.
xTrader1
07-19-2010, 12:37 PM
Regarding play sounds - are you sure they are not asynchronous. It's very easy to check.
More generally - I would bet that implementing multithreading indicators would require much more intimate knowledge of NT internals we have.
supernatural
07-19-2010, 03:35 PM
If I play a sound for each bar in my indicator (at the end of the OnBarUpdate method), I hear the sound first then about half a second later, I see the corresponding bar appearing on the chart (the one that triggered that sound), so apparently they're not asynchronous. Playing the sound in a separate thread doesn't really improve anything.
By multithreaded indicator, I just mean I would spawn a few threads when the indicator is created (for example in the OnStartUp method) and then feed them custom calculations to be executed in parallel on a multiple core machine. I don't really need to know NT internals for that, just that it let me create threads that actually execute asynchronously.
aviat72
07-19-2010, 08:13 PM
If I play a sound for each bar in my indicator (at the end of the OnBarUpdate method), I hear the sound first then about half a second later, I see the corresponding bar appearing on the chart (the one that triggered that sound), so apparently they're not asynchronous. Playing the sound in a separate thread doesn't really improve anything.
By multithreaded indicator, I just mean I would spawn a few threads when the indicator is created (for example in the OnStartUp method) and then feed them custom calculations to be executed in parallel on a multiple core machine. I don't really need to know NT internals for that, just that it let me create threads that actually execute asynchronously.
There is another thread where NT support confirmed that playsound happens aychnc.
The system Pivots indicator has an example of asynchronous threads invoked from within NT. Do not expect any support though.
if (!isDailyDataLoaded)
{
if (priorDayHLC == HLCCalculationMode.DailyBars && Bars.BarsType.IsIntraday)
{
Enabled = false;
System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(GetBarsNow));
return;
}
existsHistDailyData = false;
isDailyDataLoaded = true;
}
supernatural
07-20-2010, 11:29 AM
That's interesting! Did anyone succeed in running multiple threads concurrently (across multiple cores) this way?