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!
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
NinjaTrader
Determing NT8 Chart Trader Selected Account
Collapse
X
-
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 dcriador, Today, 01:43 AM
|
1 response
5 views
0 likes
|
Last Post
by dcriador
Today, 01:46 AM
|
||
Started by louiseruch, Today, 01:11 AM
|
0 responses
1 view
0 likes
|
Last Post
by louiseruch
Today, 01:11 AM
|
||
Started by kujista, Today, 12:39 AM
|
0 responses
5 views
0 likes
|
Last Post
by kujista
Today, 12:39 AM
|
||
Started by tonynt, 05-21-2019, 06:27 AM
|
11 responses
536 views
1 like
|
Last Post Today, 12:37 AM | ||
Started by fitspressotablettry, Today, 12:36 AM
|
0 responses
1 view
0 likes
|
Last Post Today, 12:36 AM |
Comment