Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Determing NT8 Chart Trader Selected Account
Collapse
X
-
This is very useful. One change I had to make when using this code was to use ChartControl.Dispatcher.Invoke which waits for completion of the invoked thread (synchronous) before continuing, This eliminated race conditions where sometimes the program used the old value of xAlselector because the ChartControl.Dispatcher.InvokeAsync thread (asynchronous) had not completed.Originally posted by NinjaTrader_AlanP View Post
-
NT8 is multi threaded. Click here for more details.
In Alan's example indicator, OnBarUpdate() and the Chart Trader Account Selector object run on different threads. So the ChartControl.Dispatcher.InvokeAsync((Action)(() => {} call is used to ensure that the code within the {} braces runs on the ChartControl thread asynchronously which is where the Chart Trader Account Selector object is. This is as per the NT8 documentation recommendions to use Dispatcher.InvokeAsync() calls to any internal NinjaTrader actions to avoid potential deadlock scenarios in the script.
However, in my context I put Alan's exact code to get the Account Selector into my custom indicator which is a MouseClick event handler. I got a race condition. The code within ChartControl.Dispatcher.InvokeAsync {} did not finish before the next line of code in the MouseClick handler causing it to use the old value of Account Selector.
So my first solution was to use ChartControl.Dispatcher.Invoke {} which waits for the code to be executed before moving on to the next line of code. However the MouseClick event handler is already running on the correct thread! So the better solution, for my context, was to not call ChartControl.Dispatcher.AsyncInvoke {} or ChartControl.Dispatcher.Invoke {}.Last edited by trader-ap; 08-24-2022, 02:27 AM.
Comment
-
Thanks trader-ap thanks for the feedback, perhaps NinjaTrader_AlanP will share his indicator with us.
Comment
-
Alan's example indicator is on the attachment
Here is another example of code (see the attachment on the post) to get Chart Trader Account. In this example the Account Selector is accessed through a ButtonClick handler and therefore does not require the use of Invoke calls.
https://ninjatrader.com/support/foru...98#post1055898
The same solution that I ended up with for my Mouse Event handler.Last edited by trader-ap; 08-24-2022, 02:55 AM.
- Likes 1
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
596 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
343 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
103 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
556 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
554 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment