Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trader Control - How to reset my code when user clicks on the Chart Tabs

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

    Trader Control - How to reset my code when user clicks on the Chart Tabs

    Hi,

    I have added a WFP control to the Chart Trader grid using the code below as a start point

    grChartTraderGrid = (Window.GetWindow(ChartControl.Parent).FindFirst(" ChartWindowChartTraderControl") as ChartTrader).Content as System.Windows.Controls.Grid;


    technique is also partially demonstrated here: https://ninjatrader.com/support/help...tTraderControl

    The Problem I am facing is when the user clicks on the Chart Tabs to change to a different instrument.

    How do I subscribe to a event so when the User changes the chart using the tabs in the bottom of the chart window I can reset my code for the new selected Chart/Instrument?

    #2
    Hello jmneto,

    Thank you for the question.

    I have attached a modified version of the following sample that includes InvokeAsync: https://ninjatrader.com/support/foru...7&postcount=21

    The event is the SelectionChanged event on the charts MainTabControl object.

    Code:
    Chart chartWindow = Window.GetWindow(ChartControl.Parent) as Chart;
    chartWindow.MainTabControl.SelectionChanged += MySelectionChangedHandler;
    I look forward to being of further assistance.
    Attached Files
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you this information allowed me to move forward.

      Comment


        #4
        Hi,
        In your sample, event handler MySelectionChangedHandler. What is the best way to figure which TAB we are moving from and which one we are going to? Like a tab index or similar?

        Comment


          #5
          Hello jmneto,

          That would likely depend on the intended use, what is the need to know the tab, to change the contents of the item or just to hide the item?

          The sample simply shows hiding the button based on the selection. In the sample it specifically checks:
          Code:
          temp.ChartControl == ChartControl
          Or the tab selected against the indicators ChartControl where it is applied. This would be checking one instance against another which should work to know if the tab is the indicators tab or not.

          If you are trying to do something more complex, you can use the other objects from that temp variable to compare against the Indicator variables such as
          Code:
           temp.Instrument

          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment


            #6
            Hi Jesse,
            Thx again, but I figure out using :

            System.Windows.Controls.TabControl tc = sender as TabControl;
            if (tc == null) return;

            Print("Clicked on:" + tc.SelectedIndex)

            Comment


              #7
              Hi Jesse, I ran into another need.

              Let's say I have 5 Tabs with 5 same instruments loaded

              for example in

              else if (State == State.DataLoaded)
              {

              if I run the code below I can get the tabItem in Item opposition [0]

              TabItem tabItem = chartWindow.MainTabControl.Items[0] as TabItem;
              if (tabItem == null) return;

              ChartTab temp = tabItem.Content as ChartTab;
              if (temp == null) return;

              How can I get the current tabItem

              For the current chart tab


              I would need something like this


              TabItem tabItem = chartWindow.MainTabControl.Items[CurrentTabIndex] as TabItem;


              I tried chartWindow.MainTabControl.SelectedIndex; but it does not work since at first time NT loads, for all loaded chart tabs it returns the value of the current selected tab and not the tab where the chart/instrument is loaded.

              Comment


                #8
                Hello jmneto,

                You can access the selected tab the same way you do in the event handler, the tabs content needs to be cast to a ChartControl which can then be compared. The TabManager has a SelectedItem property which will produce the TabItem:

                Code:
                TabItem t = chartWindow.MainTabControl.SelectedItem as TabItem;
                ChartTab temp = t.Content as ChartTab;
                The remainder of the check to see if ChartControl is equal would be the same as the event handler, you could do this check right after the button was created if necessary.

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Thx, I am all set now.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by RideMe, 04-07-2024, 04:54 PM
                  5 responses
                  28 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by f.saeidi, Today, 08:13 AM
                  1 response
                  4 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by DavidHP, Today, 07:56 AM
                  1 response
                  6 views
                  0 likes
                  Last Post NinjaTrader_Erick  
                  Started by kujista, Today, 06:23 AM
                  3 responses
                  9 views
                  0 likes
                  Last Post kujista
                  by kujista
                   
                  Started by Mindset, Yesterday, 02:04 AM
                  2 responses
                  18 views
                  0 likes
                  Last Post NinjaTrader_RyanS  
                  Working...
                  X