Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Custom button and a few chart tabs

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

    Custom button and a few chart tabs

    I am not sure is it supported or not so any help will be appreciated.
    To demostrate my issue I have created the script (attached) based on the following article: http://ninjatrader.com/support/helpG...th_buttons.htm

    Unfortunately I have not found a way how to display only the button for the active tab. Without that it looks a bit confusing - two identical buttons and user cannot define which one is related to the active tab:


    To reproduce it open two tabs and apply the scropt to both of them
    Attached Files

    #2
    Hello AlexGn,

    Thank you for your note.

    Attached is an example indicator that shows a button (NTMenu object) only when the originating tab is selected, that I have updated from an earlier version posted in the link below.
    http://ninjatrader.com/support/forum...ad.php?t=77869

    Update:
    This is now implemented as 'Use case #4: Custom menu added to titlebar (NTBar) variables' in the SampleWPFModifications reference sample.
    https://ninjatrader.com/support/help...ui)-modifi.htm
    Attached Files
    Last edited by NinjaTrader_ChelseaB; 06-07-2022, 12:50 PM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Chelsea,

      Thank you for your help. But looks like attached script works not as expected. At least for my usecase. Adding the indicator to the first tab works fine:

      But something is wrong with the second tab:

      Attached Files

      Comment


        #4
        Hello AlexGn,

        The behavior of this script is that the button is hidden (visibility set to collapsed) when a tab other than the originating tab is selected.

        Is this different than the behavior you are experiencing using this script?

        The code demonstrates how to work with tabs.

        If you want to show different buttons on different tabs you can do this with custom logic.

        The each TabItem in chartWindow.MainTabControl.Items is a tab. Show the visibility of the button when the tab you would like is selected.

        My suggestion would be to add one indicator per tab and only have that tab show the button from the indicator added to that tab. This would be instead of having one indicator for all tabs.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          My idea was to open a few tabs with different instruments and add to the each one my script (with custom button). I think it makes sense. But for such usecase your script looks a bit incorrect because it does not display button for the second tab. Correct script should display proper button related to the active tab (not nothing like in yours and not all buttons like in mine)

          Comment


            #6
            Hello AlexGn,

            My script does not create a button for each tab.
            This example shows how to work with tabs. The script will only show a button on the tab that the indicator is added to (that the button originated from). May I confirm that this is the behavior that you are experiencing with this script?

            You would need to write logic to show the correct button when the desired tab is selected if this is what you want your script to do.

            In the support department at NinjaTrader we do not create, debug, or modify code for our clients. This is so that we can maintain a high level of service for all of our clients as well as our partners.

            You can contact one of our professional NinjaScript Consultants who would be eager to create or modify this script at your request or assist you with your script..
            Would you like a link to a list of consultants that would be able to create the logic you want for your script?

            This thread will remain open for any community members that would like to develop this logic as a courtesy.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Chelsea,

              No need for help anymore, your script was helpful enough and I have implemented desired logic already. Thanks a lot!

              Comment


                #8
                Hello,

                I've updated this example for better coding practice. The Dispatcher.Invoke is now ChartControl.Dispatcher.BeginInvoke.

                Note: As best practice, always be sure to use Dispatcher.BeginInvoke() to ensure that your action is one asynchronously to any internal NinjaTrader actions. Calling Dispatcher.Invoke() (synchronous) can potentially result in a deadlock scenario.
                Last edited by NinjaTrader_ChelseaB; 06-07-2022, 12:39 PM.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hello,

                  This script has been updated once more to use Dispatcher.InvokeAsync instead of Dispatcher.BeginInvoke which has been deprecated.

                  Update:
                  This is now implemented as 'Use case #4: Custom menu added to titlebar (NTBar) variables' in the SampleWPFModifications reference sample.
                  https://ninjatrader.com/support/help...ui)-modifi.htm
                  Attached Files
                  Last edited by NinjaTrader_ChelseaB; 06-07-2022, 12:49 PM.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks chelsea for sharing the example below. I have been expanding the ideas for my own purposes and the relation of the tabs to the main window thread.
                    what i was experiencing was in adding my indicator to multiple tabs i was only seeing one menu appear for one tab - for the other tabs where the indicator was added when selecting those instruments/tabs no menu appeared.
                    So in delving into the code i removed the code segment

                    foreach (DependencyObject item in chartWindow.MainMenu)
                    ...
                    if (isToolBarButtonAdded)

                    section

                    as i wondered other than the first tab were the other tabs being setup properly.

                    In removing this i now have each tab that has the indicator loaded with the menu item present.
                    The issue is on first loading and starting ninja multiple menu items of the same name appear but when a tab is selected the multiple names clear and there is only one.

                    Can you point me to the MSDN microsoft area to better understand the relationship of when to make a menu visible and when a tab is selected / unselected.

                    the code at the end of InsertWPFControls

                    foreach(TabItem tab in chartWindow.MainTabControl.Items)
                    if ((tab.Content as ChartTab).ChartControl == ChartControl && tab == chartWindow.MainTabControl.SelectedItem)

                    topMenuItem1.Visibility = Visibility.Visible;

                    i wondered if this is enough or the right check to ensure a menu is visible for a selected tab.

                    Any pointers would be appreciated as this is a framework that probably needs more clarity in order to handle adding toolbars with alot of subtle checks and calls to make. I note that you said a toolbar on the chart is perhaps a better way to go and whether from a design point of view given the main chart is a separate thread whether this would/should be the way i should develop this

                    thanks

                    Comment


                      #11
                      Hello soulfx,

                      I don't think there will be a microsoft document on this exactly. Are you wanting links to how to use a foreach, how to use a wpf tab control, and how to set the visibility on a wpf control?

                      foreach - https://msdn.microsoft.com/en-us/library/ttw7t8t6.aspx
                      TabControl - https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx
                      TabItem - https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx
                      Visibility - https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx


                      I added this loop because it made sense to me that a button would only be visible for the chart it would affect.
                      (The indicator is a child of the chart, the button is a child of the indicator. The button press by default will only affect the chart tab that the indicator is applied to)

                      This loops through chartWindow.MainTabControl.Items. One of these items is the chart this indicator was added to. If the ChartControl of the indicator matches the ChartControl of the currently selected tab, then we know that the current tab is the tab with the indicator on it.

                      An event handler is added to the selection change event for the tab control to run this check. If this is the tab with the indicator then set the visibility to visible. If not, i set it to collapsed so that it is hidden but still occupies that space.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Hello,

                        I've updated this indicator with a geometry object for the icon and changed the name.

                        Update:
                        This is now implemented as 'Use case #4: Custom menu added to titlebar (NTBar) variables' in the SampleWPFModifications reference sample.
                        https://ninjatrader.com/support/help...ui)-modifi.htm
                        Attached Files
                        Last edited by NinjaTrader_ChelseaB; 06-07-2022, 12:49 PM.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hello,

                          A forum member has let me know this script adds the MySelectionChangedHandler to the MainTabControl.SelectionChanged event twice. This shouldn't cause any errors, but leaving the handler working is bad practice.

                          I've updated to remove the duplicate assignment.

                          Update:
                          This is now implemented as 'Use case #4: Custom menu added to titlebar (NTBar) variables' in the SampleWPFModifications reference sample.
                          https://ninjatrader.com/support/help...ui)-modifi.htm
                          Attached Files
                          Last edited by NinjaTrader_ChelseaB; 06-07-2022, 12:48 PM.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Hello,

                            A forum member has let me know this script does not allow the menu to be added when adding a second instance of the indicator to a new tab (or new chart).

                            I was using the AutomationID to see if the menu already exists on the toolbar to prevent it from being added twice.

                            To correct this, I'm just making the AutomationIDs unique by adding the date and time to the string.

                            Update:
                            This is now implemented as 'Use case #4: Custom menu added to titlebar (NTBar) variables' in the SampleWPFModifications reference sample.
                            https://ninjatrader.com/support/help...ui)-modifi.htm
                            Attached Files
                            Last edited by NinjaTrader_ChelseaB; 06-07-2022, 12:49 PM.
                            Chelsea B.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by TraderBCL, Today, 04:38 AM
                            2 responses
                            16 views
                            0 likes
                            Last Post TraderBCL  
                            Started by martin70, 03-24-2023, 04:58 AM
                            14 responses
                            106 views
                            0 likes
                            Last Post martin70  
                            Started by Radano, 06-10-2021, 01:40 AM
                            19 responses
                            609 views
                            0 likes
                            Last Post Radano
                            by Radano
                             
                            Started by KenneGaray, Today, 03:48 AM
                            0 responses
                            5 views
                            0 likes
                            Last Post KenneGaray  
                            Started by thanajo, 05-04-2021, 02:11 AM
                            4 responses
                            471 views
                            0 likes
                            Last Post tradingnasdaqprueba  
                            Working...
                            X