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 Max238, Today, 01:28 AM
            1 response
            22 views
            0 likes
            Last Post CactusMan  
            Started by giulyko00, Yesterday, 12:03 PM
            2 responses
            10 views
            0 likes
            Last Post giulyko00  
            Started by r68cervera, Today, 05:29 AM
            0 responses
            4 views
            0 likes
            Last Post r68cervera  
            Started by geddyisodin, Today, 05:20 AM
            0 responses
            6 views
            0 likes
            Last Post geddyisodin  
            Started by JonesJoker, 04-22-2024, 12:23 PM
            6 responses
            38 views
            0 likes
            Last Post JonesJoker  
            Working...
            X