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!
See more
See less

Partner 728x90

Collapse

Determing NT8 Chart Trader Selected Account

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Originally posted by NinjaTrader_AlanP View Post
    Hello D Trader,

    I have put together an indicator which will print the current account selected in the Chart Trader drop down and attached the file.

    Please let us know if you need further assistance.
    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.

    Comment


      #17
      Sounds like French trader-ap Do yo have a copy of the indicator with that changed?

      Comment


        #18
        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


          #19
          Thanks trader-ap thanks for the feedback, perhaps NinjaTrader_AlanP will share his indicator with us.

          Comment


            #20
            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.

            Comment


              #21
              Is there a way to get the "status" of Chart Trader?

              Like is it On, Hidden or off?

              Comment


                #22
                Hello cre8able,

                ChartControl.Properties.ChartTraderVisibility
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by dcriador, Today, 01:43 AM
                1 response
                5 views
                0 likes
                Last Post dcriador  
                Started by louiseruch, Today, 01:11 AM
                0 responses
                1 view
                0 likes
                Last Post louiseruch  
                Started by kujista, Today, 12:39 AM
                0 responses
                5 views
                0 likes
                Last Post kujista
                by kujista
                 
                Started by tonynt, 05-21-2019, 06:27 AM
                11 responses
                536 views
                1 like
                Last Post NinjaTrader_Jason  
                Started by fitspressotablettry, Today, 12:36 AM
                0 responses
                1 view
                0 likes
                Last Post fitspressotablettry  
                Working...
                X