Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to Read from Chart Trader's Instrument Selector

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

  • Rainmakersg
    replied
    Hi Chelsea, thanks very much. It works!

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello Rainmakersg,

    You could try setting the ComboBox SelectedIndex or SelectedValue.

    Leave a comment:


  • Rainmakersg
    replied
    Hi Chelsea, thanks so much for the reply. Yes it works now!

    I have a suggestion if you don't mind. I am thinking your new indicator "ChartTraderUIElementsFromAutomationIDsIndicatorExa mple_NT8.zip" has exactly the same name as the old one and it would be helpful to add to the name a version number or date of release so people will not be confused and know which is the latest version.

    I also hope you can be kind enough to answer the following question.
    I have 2 panels, each loaded with a different instrument. They both share the same chart trader. I have a buy button on each panel's main chart to open trades. After I click the buy button in a panel, a trade is opened. However, in order to see the order lines displayed in the panel, I need to select the correct instrument from the chart trader's instrument selector. This is a hassle and quite time consuming and I run the risk of clicking the wrong combo box in the midst of a live trade as they are very close to one another.

    Is it possible to use Ninjascript to switch the instrument selected on the chart trader?
    I wish to bind this code to the buy button so that whenever I click on the buy button in a panel, it will open a trade, and then it will run the code to switch to the corresponding instrument so that the corresponding order lines will be displayed in the panel.

    Your assistance would be very much appreciated.​
    Last edited by Rainmakersg; 08-30-2024, 04:19 AM.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello Rainmakersg,

    Well.. this was not quite what I was expecting..

    The chart trader instrument selector doesn't appear to be an actual InstrumentSelector object but is just a ComboBox. Likely because it's just listing instruments on this specific chart (not all instruments) and doesn't actually change the instrument of the chart.

    So, I casted as a ComboBox just to use the .SelectionChanged event, and when the event fires, I still reference the <ChartTrader>.Instrument (which is updated).
    Attached Files

    Leave a comment:


  • Rainmakersg
    replied
    Originally posted by NinjaTrader_ChelseaB View Post
    Hello Rainmakersg,

    Try using the <NinjaTrader.Gui.Chart.ChartTrader>.Instrument instead. The forum post below has sample code.
    https://forum.ninjatrader.com/forum/...91#post1285491
    Hi Chelsea, thanks for the reply. After applying the code, I am able to read the instrument from Chart Trader's instrument selector upon loading the indicator.

    My next step is to be able to detect updates to the instrument selector whenever a new instrument is selected from the list.

    I am using the following for reference:
    PHP Code:
    Detecting updates in Chart Trader's account selector -> myAccountSelector.SelectionChanged
    Detecting updates in Chart Trader's quantity selector -> myQuantitySelector.ValueChanged 
    

    I tried the following for Chart Trader's instrument selector:
    PHP Code:
    myChartTraderControl.SourceUpdated
    myChartTraderControl.TargetUpdated 
    


    However, both don't work. Can you advise how to get it working?
    Thanks.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello Rainmakersg,

    Try using the <NinjaTrader.Gui.Chart.ChartTrader>.Instrument instead. The forum post below has sample code.

    Leave a comment:


  • How to Read from Chart Trader's Instrument Selector

    Hi,

    I have a chart with 2 panels, each loaded with a different instrument. Both of them share a chart trader. As such, I need to read from the chart trader's instrument selector in order to know which instrument it is pointing to.

    I have a working code for reading from the main chart's instrument selector:

    PHP Code:
            private NinjaTrader.Gui.Tools.InstrumentSelector    myInstrumentSelector;
            private Instrument                                   myInstrument;
            
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                 .
                 .
                }
    
                else if (State == State.DataLoaded)
                {
                    FindAssignUIElementsByAutomationID();
                }
                
                else if (State == State.Terminated)
                {
                    if (ChartControl != null)
                    {
                        ChartControl.Dispatcher.InvokeAsync((Action)(() =>
                        {
                            if (myInstrumentSelector != null)
                            {
                                myInstrumentSelector.InstrumentChanged -= OnInstrumentChanged;
                            }
                        }));
                    }
                }
            }
    
    
            private void FindAssignUIElementsByAutomationID()
            {
                if (ChartControl != null)
                {
                    ChartControl.Dispatcher.Invoke((Action)(() =>
                    {
                        myInstrumentSelector                         = Window.GetWindow(ChartControl.OwnerChart).FindFirst("ChartWindowInstrumentSelector") as InstrumentSelector;
                        myInstrumentSelector.InstrumentChanged       += OnInstrumentChanged;
                        myInstrument                                 = myInstrumentSelector.Instrument;
                        
                        Print("Instrument loaded : " + myInstrument);
                    }));
                }
            }
            
    
            private void OnInstrumentChanged(object sender, EventArgs e)
            {
                myInstrument = sender as Cbi.Instrument;
                
                Print("Instrument changed to : " + myInstrument);
            }
            
            
            protected override void OnBarUpdate()
            {
                if ((State == State.Historical && CurrentBar != Count - 2))
                    return;
            
                if (myInstrumentSelector == null)
                {
                    FindAssignUIElementsByAutomationID();
                }
                
                Print ("myInstrument : " + myInstrument);
            }
            
        }&#8203; 
    


    When I replace the Automation ID from
    PHP Code:
    ChartWindowInstrumentSelector 
    
    to
    PHP Code:
    ChartTraderControlInstrumentSelector 
    
    , I get the error Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.

    Can you advise what should I do to get it working?

    Thanks so much.

Latest Posts

Collapse

Topics Statistics Last Post
Started by SalmaTrader, 07-07-2026, 10:26 PM
0 responses
35 views
0 likes
Last Post SalmaTrader  
Started by CarlTrading, 07-05-2026, 01:16 PM
0 responses
20 views
0 likes
Last Post CarlTrading  
Started by CaptainJack, 06-17-2026, 10:32 AM
0 responses
13 views
0 likes
Last Post CaptainJack  
Started by kinfxhk, 06-17-2026, 04:15 AM
0 responses
19 views
0 likes
Last Post kinfxhk
by kinfxhk
 
Started by kinfxhk, 06-17-2026, 04:06 AM
0 responses
22 views
0 likes
Last Post kinfxhk
by kinfxhk
 
Working...
X