• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Custom button and a few chart tabs

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

  • NinjaTrader_ChelseaB
    replied
    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.
    Attached Files

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    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.
    Attached Files

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello,

    I've updated this indicator with a geometry object for the icon and changed the name.
    Attached Files
    Last edited by NinjaTrader_ChelseaB; 09-27-2016, 07:40 AM.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    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.

    Leave a comment:


  • soulfx
    replied
    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

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello,

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

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    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.
    Attached Files

    Leave a comment:


  • AlexGn
    replied
    Chelsea,

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

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    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.

    Leave a comment:


  • AlexGn
    replied
    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)

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    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.

    Leave a comment:


  • AlexGn
    replied
    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

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    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
    Attached Files

    Leave a comment:


  • AlexGn
    started a topic Custom button and a few chart tabs

    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

Latest Posts

Collapse

Topics Statistics Last Post
Started by NT-Roland, Today, 10:03 AM
0 responses
3 views
0 likes
Last Post NT-Roland  
Started by kevinfloresz, Today, 09:46 AM
0 responses
10 views
0 likes
Last Post kevinfloresz  
Started by tvaughan4, 12-13-2019, 10:46 PM
2 responses
19 views
0 likes
Last Post tvaughan4  
Started by digibob, 12-13-2019, 10:01 PM
3 responses
13 views
0 likes
Last Post digibob
by digibob
 
Started by ldissinger, Yesterday, 12:55 PM
1 response
21 views
0 likes
Last Post ldissinger  
Working...
X