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

(State == State.Terminated) ChartControl == null

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

    (State == State.Terminated) ChartControl == null

    Hello

    version 8.0.7.1

    In OnStateChange() when (State == State.Terminated) ChartControl always is null.
    How I can remove my UI items from toolbar now on indicator termination??? E.g. when user closes chart tab in multi tab window.
    I need to execute this
    ChartControl.Dispatcher.InvokeAsync((Action)(() => { ... }

    #2
    Hello ren37,

    Thanks for opening the thread.

    ChartControl will not always be null in State.Terminated. If you invoke the method to dispose of your objects within a null check for ChartControl, you will prevent issues where your added UI items will be readded when reloading NinjaScripts.

    These implications are handled in our colleague Chelsea's sample scripts to modify WPF elements in a chart. I would suggest to review these samples for how you can handle these implications on your end.

    You can find these sample scripts here: http://ninjatrader.com/support/forum...327#post499327

    Please let me know if I may be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Jim,

      Just tested ChartCustomToolbarExample_NT8
      To not write too many letters just see images. I think you guessed why controls was nevertheless removed.
      I had no such issues in 8.0.6.0 and prior versions. Any suggestions?
      Attached Files
      Last edited by ren37; 07-06-2017, 02:00 PM.

      Comment


        #4
        Hello ren37,

        Sorry for any confusion.

        I was not claiming that ChartControl wouldn't be null when changing tabs. I was simply stating that while reloading NinjaScripts with F5, you would recreate the UI items if you did not dispose of the menu items within a null check for ChartControl in State.Terminated. I had tested this before I made my post, and this should still be minded. You can test this on your end by commenting out the code in State.Terminated in one of the samples and reloading the NinjaScript with F5.

        As for directing you towards a solution when changing tabs, the sample scripts provide a solution to that matter by creating a TabChangedHandler attached to chartWindow.MainTabControl.SelectionChanged.

        As the ChartCustomToolBarExample sample is a lot more cumbersome than the ChartCustomSidePanelExample sample, I would recommend to review the implementation in the ChartCustomSidePanelExample.

        If there is an issue in the examples that you would like us to look over, please let us know.
        JimNinjaTrader Customer Service

        Comment


          #5
          Jim

          Where did you find I'm asking about handle tab changing? I know how to do that.
          I have issue when user CLOSES tab in multi tab window with my indicator.
          Indicator terminated and I need to remove my buttons from main toolbar (where all NT chart controls are). But I can't do that because ChartControl is null on Terminated state. So my button stays on main toolbar.
          If indicator being terminated after F5 pressed ChartControl is not null and all is fine.

          Comment


            #6
            Hello ren37,

            In the sample scripts, when a tab is changed or closed, the TabChangedHandler will either recreate or remove the menu items. The sample scripts do not handle this case in State.Terminated. The code in State.Terminated is only relevant for reloading the NinjaScript as we have discussed.

            Code:
            private bool TabSelected()
            {
            	bool tabSelected = false;
            
            	// loop through each tab and see if the tab this indicator is added to is the selected item
            	foreach (System.Windows.Controls.TabItem tab in chartWindow.MainTabControl.Items)
            		if ((tab.Content as ChartTab).ChartControl == ChartControl && tab == chartWindow.MainTabControl.SelectedItem)
            			tabSelected = true;
            
            	return tabSelected;
            }
            
            private void TabChangedHandler(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
            {
            	if (e.AddedItems.Count <= 0)
            		return;
            
            	tabItem = e.AddedItems[0] as System.Windows.Controls.TabItem;
            	if (tabItem == null)
            		return;
            
            	chartTab = tabItem.Content as NinjaTrader.Gui.Chart.ChartTab;
            	if (chartTab == null)
            		return;
            	
            	if (TabSelected())
            		InsertWPFControls();
            	else
            		RemoveWPFControls();
            	
            }
            I've created a quick demo where I have added a print to the TabChangedHandler where WPF controls are created and removed: https://www.screencast.com/t/ifAFJRPtnH

            If there is an issue with the sample scripts that you are describing, could you provide me some steps to take to better understand the case you are running into? As far as I have tested, the samples handle all of the cases that need to be minded.
            JimNinjaTrader Customer Service

            Comment


              #7
              Hi Jim

              At my end ChartControl is always null if I close chart tab (even in on tab changed handler as you advised). Now I store chartWindow reference and remove my controls using this reference in tab handler.

              It's very strange why ChartControl in current version is null on termination. Why developers did that? In prior versions it's not.
              Also. I think it's not a good idea to remove/add controls on each tab changing instead of just show/hide them.

              Comment


                #8
                Hi ren37,

                I can't provide much commentary on why/when ChartControl is null. All the documentation states is that it can only be expected to be available when a NinjaScript is initiated from a chart.

                Ref: https://ninjatrader.com/support/help...artcontrol.htm

                The techniques done for modifying WPF elements in a chart fall under our undocumented and unsupported category. Unsupported does not necessarily mean "don't do this" so much as a general advisory meaning "You're on your own," and "Subject to change." This keeps the development team from locking themselves into a certain implementation that they may wish to change later on.

                Even though these modification are technically unsupported, we do like to share some possibilities on how these modifications can be accomplished as they are very common for clients and vendors to use.

                If you have a better idea of how these techniques can be done, we would certainly like to see your implementation if there is something that we can improve upon on our end.

                Best of luck with your development!
                JimNinjaTrader Customer Service

                Comment


                  #9
                  Yes, Jim, I have one.
                  Don't call OnRender() 20+ times while starting dragging by mouse.
                  Have sent this issue to your product team but got no answer at all.
                  Some customers complaint on this.

                  Comment


                    #10
                    Hi ren37,

                    I've submitted a feature request on your behalf. I'll update this post with the ticket ID when I receive it.

                    Ticket ID: SFT-2506

                    The ticket ID can be noted in the Release Notes of NinjaTrader that includes the feature.

                    Release Notes: https://ninjatrader.com/support/help...ease_notes.htm

                    Keep in mind that feature requests are up to the development team and their priorities to consider implementing.

                    Thanks for sharing your feedback.
                    Last edited by NinjaTrader_Jim; 07-11-2017, 09:16 AM.
                    JimNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Skifree, Today, 03:41 AM
                    3 responses
                    12 views
                    0 likes
                    Last Post Skifree
                    by Skifree
                     
                    Started by traderqz, Yesterday, 09:06 AM
                    5 responses
                    32 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by guillembm, Today, 11:25 AM
                    1 response
                    6 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by owensd, 04-21-2024, 11:34 PM
                    9 responses
                    34 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by trilliantrader, 04-10-2024, 09:33 PM
                    7 responses
                    25 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Working...
                    X