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

list chart data series in add-on

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

    list chart data series in add-on

    I'm working on an add-on that resides on the chart trader panel. I've been trying to access the list of data series on the chart tab so I can create a custom list box containing these, but can't figure it out. Is there a way to list these? My ultimate goal is to create a custom ListBox or InstrumentSelector that replicates the default ChartTrader instrument selector behavior of limiting to charted instruments.

    Thanks,
    Nick

    #2
    Hello Nick,

    If this is something you are adding to the WPF from an indicator, you could use an InstrumentSelector.

    Below is a link to an example that uses an InstrumentSelector.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I am adding custom controls to the WPF from an AddOn. In my current iteration I have an InstrumentSelector created and working, but as mentioned, it's not filtered and I don't see how to filter it to specific instruments. I'd like it to be contextual to the chart panel.

      So my thought process was
      A) Since there doesn't seem to be a way to filter the instrument selector presented to a user, I would need to create a custom list/combo box.
      B) If I tried to create my own custom listbox, I would need to iterate a list of data series on the chart panel, which I also can not see a way to do in addon code but there must be an object somewhere I can reference that contains this list?

      Comment


        #4
        Hello NickyD,

        An InstrumentSelector would be the same as the Data Series selector.

        I agree, a drop-down with a filtered list of instruments would be a custom ComboBox or ListBox.

        The ChartControl has BarsArray collection of all of the ChartBars added in the Data Series window of the chart.

        Try looping these.

        foreach(ChartBars bars in ChartControl.BarsArray)
        {
        Print(bars.Bars.Instrument);
        }
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5

          An update for post's thread.

          There appear to be threading issues (that are beyond my skillset) with the suggested foreach(ChartBars bars in ChartControl.BarsArray) when executing from OnWindowCreated(). The Bars object returned from BarsArray in the foreach loop will return as NULL when a chart window is first created. I could never get it straightened out. I did stumble across the following properties which were accessible without issue, if I attached to the ChartControl.Loaded event. These will give you a list of the data series added to the chart, upon initial window creation at least. I didn't test beyond that because I came across a better solution which I'll post next. I don't even know if this is a correct/valid approach, I just wanted to point out the BarsArray Properties.

          Code:
          protected override void OnWindowCreated(Window window)
          {[INDENT]// the main chart window
          chartWindow = window as Gui.Chart.Chart;
          
          //Print("OnWindowCreated - " + window.Title );
          
          // if not a chart, do nothing
          if (chartWindow == null) {[/INDENT][INDENT=2]Print("OnWindowCreated - " + window.Title + " is not a chart window" );
          return;[/INDENT][INDENT]}
          else {[/INDENT][INDENT=2]Print("OnWindowCreated - " + window.Title + " is a chart window" );
          Print("Attach event when chart control is loaded" );
          chartWindow.ActiveChartControl.ChartTab.ChartContr ol.Loaded += new RoutedEventHandler(ListInstruments);[/INDENT][INDENT]}[/INDENT]
           
          }
          
          
          private void ListInstruments (object sender, RoutedEventArgs e)
          {[INDENT]newChartToList = sender as Gui.Chart.ChartControl;
          
          if ( newChartToList == null ) {[/INDENT][INDENT=2]Print("cast failed");
          return;[/INDENT][INDENT]}
          else[/INDENT][INDENT=2]Print("cast succeeded");
          
          Print("BarsArrayCount: " + newChartToList.BarsArray.Count );
          
          for ( int a = 0; a < newChartToList.BarsArray.Count; a++ ) {
          Print("There should be an instrument here:");
          
          Print( newChartToList.BarsArray[a].Properties.Instrument );
          Print( newChartToList.BarsArray[a].Properties.DisplayName );[/INDENT][INDENT]
          }[/INDENT]
           }

          Comment


            #6
            Ultimately what I ended up going with since I wanted a custom combobox that mimicked the default chart trader instrument selector was setting my custom combobox item source property to the default chart trader instrument selector ItemSource. This binds the two and seems to yield my desired functionality.

            So I lookup the default control:
            Code:
            instrumentSelectorNick = chartTraderGrid.FindFirst("ChartTraderControlInstrumentSelector") as ComboBox;
            Then create my custom control and set the ItemSource:
            Code:
            if ( customInstrumentSelector == null )[INDENT]customInstrumentSelector = new ComboBox();[/INDENT]
             
            chartTraderGrid.Dispatcher.InvokeAsync((System.Act ion)(() =>
            {[INDENT]customInstrumentSelector.ItemsSource = instrumentSelectorNick.ItemsSource;[/INDENT]
             }));
            Then I add my custom combobox to my wpf grid and it seems to work pretty well.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by bmartz, 03-12-2024, 06:12 AM
            4 responses
            31 views
            0 likes
            Last Post bmartz
            by bmartz
             
            Started by Aviram Y, Today, 05:29 AM
            4 responses
            12 views
            0 likes
            Last Post Aviram Y  
            Started by algospoke, 04-17-2024, 06:40 PM
            3 responses
            28 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by gentlebenthebear, Today, 01:30 AM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by cls71, Today, 04:45 AM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X