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

How to Find Selected Instrument in Chart Trader

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

    How to Find Selected Instrument in Chart Trader

    Creating Custom Buttons for Chart Trader.

    How do I find the Instrument that is selected for the Chart/Chart Trader?

    I figured out how to find the selected account for Chart Trader. Using the same approached I can not find the instrument.

    Code:
    AccountSelector accountSelector = Window.GetWindow(ChartControl.Parent).FindFirst("ChartTraderControlAccountSelector") as AccountSelector;
    Print(accountSelector.SelectedAccount.ToString());
    InstrumentSelector instrumentSelector = Window.GetWindow(ChartControl.Parent).FindFirst("ChartTraderControlInstrumentSelector") as InstrumentSelector;
    Print("insturment: " + instrumentSelector.Instrument.ToString());
    Last edited by DoctorPurpleApe; 03-18-2022, 09:17 AM. Reason: Removed random space in ChartTrader..., was C hartTrader...

    #2
    Hello DoctorPurpleApe,

    Thank you for your note.

    You're definitely on the right track there.

    I'm attaching a simple example indicator that finds the InstrumentSelector and prints the current instrument to the log.

    Please let us know if we may be of further assistance to you.
    Attached Files
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Thank you so much for the code. Changed the FindFirst parameter to "ChartWindowInstrumentSelector" and it worked great.

      The comment //You have to put the stuff below within this ChartControl.Dispatcher.InvokeAsync((Action)(() =>, because you are trying to access something on a different thread. actually helped solved a new problem I had with my code, so I am really glad you attached the file.

      Comment


        #4
        Will this work if you have multiple TABs in a chart, or will it always default to the first chart?

        Comment


          #5
          Hello MisterTee,

          Thank you for your note.

          I tested this indicator on a chart with multiple tabs and it seemed to print the instrument on the tab where I applied the indicator, even if it wasn't the first tab in the chart window. If there is something more specific you are looking to achieve, please let us know and we would be glad to provide additional resources to assist.

          Thank you for your patience.
          Emily C.NinjaTrader Customer Service

          Comment


            #6
            thank you!

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by llanqui, Today, 03:53 AM
            0 responses
            6 views
            0 likes
            Last Post llanqui
            by llanqui
             
            Started by burtoninlondon, Today, 12:38 AM
            0 responses
            10 views
            0 likes
            Last Post burtoninlondon  
            Started by AaronKoRn, Yesterday, 09:49 PM
            0 responses
            15 views
            0 likes
            Last Post AaronKoRn  
            Started by carnitron, Yesterday, 08:42 PM
            0 responses
            11 views
            0 likes
            Last Post carnitron  
            Started by strategist007, Yesterday, 07:51 PM
            0 responses
            14 views
            0 likes
            Last Post strategist007  
            Working...
            X