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

[ChartStyle] Submode icons

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

    [ChartStyle] Submode icons

    Hi,

    Is it possible to set icons for submodes of a chart style? How do I do that?


    #2
    Hello @tmc_,

    Yes, Gui.Tools.NTMenuItem objects have an Icon property (the type is object) that can be set to geometry, string, or image.

    Below is a public link to the microsoft documentation.


    And a link to an example that sets an Icon property of an NTMenyItem.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      Thanks for the reply. How do I access this NTMenuItem object generated when overriding SubModes? See the attachment for a sample chart style. I would like to show the icons in submenu next to the modes.

      Attached Files

      Comment


        #4
        Hello @tmc_,

        I would recommend creating an a NTMenuItem object the same way the example I have provided you demonstrates.

        Below is a public link to the help guide on NTMenuItem.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I ended up changing the NTMenuItem icons in overridden OnRender method. However, this leads to late icon rendering, I would like to see the icons before the ChartStyle is applied. Is it possible to access ChartControl before the OnRender? Keep in mind we are talking about ChartStyle and not an Indicator.

          You can find the current solution in the attachment below.
          Attached Files

          Comment


            #6
            Hello @tmc_,

            WPF elements should not be added in OnRender.

            (edited. the example adds the controls from State.Historical instead of State.DataLoaded but really either works)
            In the example I have provided you this adds the controls in a Dispatch.InvokeAsync() run from OnStateChange when state is State.Historical.
            Last edited by NinjaTrader_ChelseaB; 07-30-2018, 07:51 AM.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              I am not adding WPF elements, just changing icons if it wasn't done yet. I know it should not be done in OnRender, that's why I have asked how to access ChartControl inside of ChartType before OnRender method. It seems to be not accessible in OnStateChange and therefore I can't use the solution you have provided.

              Comment


                #8
                Hello @tmc_,

                NTMenuItem is a WPF element. To confirm you are not creating or adding this in OnRender(), correct?

                ChartControl can be accessed in any method after the State is State.Configure.

                May I confirm you have reviewed the example I have provided you?
                Please take a look at State.Historical in this example.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Yes, correct. You can see the code in the attachment or here. I can access the class but not the object, it's under IndicatorRenderBase but I want to access it from ChartStyle. Or am I doing something wrong?
                  Last edited by @tmc_; 07-30-2018, 08:07 AM.

                  Comment


                    #10
                    Hello @tmc_,

                    Have you linked the wrong file?

                    Attached is a screenshot of what I am seeing from what you have linked.

                    This file is showing that WPF elements are being added in OnRender() which I have advised against.

                    My example demonstrates adding WPF from OnStateChange when State is State.Historical.

                    I think you have accidentally linked the wrong file. Can you link the file that adds the elements from OnStateChange that you have mentioned?
                    Attached Files
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      This is the right file. I said I can access only ChartControl class in OnStateChange(), I am working with ChartStyle, not an Indicator and the ChartControl object is under IndicatorRenderBase. That's why I worked around it by using OnRender() which passes the ChartControl object as an argument. How do I access ChartControl object in OnStateChange() of ChartStyle?

                      Comment


                        #12
                        Hello @tmc_,

                        I'm understanding your inquiry now.
                        The ChartStyle scripts don't have have a ChartControl object available to the entire script.

                        For addon type scripts like custom bar types, chart styles, custom addon windows, you would need to loop through the windows, find the window and get the ChartControl object.
                        Code:
                        protected override void OnStateChange()
                        {
                        	if (State == State.Configure)
                        	{
                        		NTWindow ntWindow;
                        
                        		foreach (Window window in NinjaTrader.Core.Globals.AllWindows)
                        		{
                        			ntWindow = (NTWindow)window;
                        
                        			window.Dispatcher.Invoke(new Action(() =>
                        			{
                        				if (ntWindow.Caption.Contains("Chart"))
                        					foreach (ChartControl cc in FindVisualChildren<ChartControl>(ntWindow))
                        						foreach (object obj in cc.ChartObjects)
                        							if (obj.GetType() == typeof(ChartBars))
                        								if ((obj as ChartBars).Properties.ChartStyle == this)
                        									thisChartControl = cc;
                        			}));
                        
                        			if (thisChartControl != null)
                        			{
                        				// you've got a ChartControl you can do whatever you want with now		
                        			}
                        		}
                        	}
                        }
                        
                        public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
                        {
                        	if (depObj != null)
                        	{
                        		for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
                        		{
                        			DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
                        			if (child != null && child is T)
                        				yield return (T)child;
                        
                        			foreach (T childOfChild in FindVisualChildren<T>(child))
                        				yield return childOfChild;
                        		}
                        	}
                        }
                        Last edited by NinjaTrader_ChelseaB; 07-30-2018, 10:26 AM.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          The name 'FindVisualChildren' does not exist in the current context. Am I missing a reference?

                          Comment


                            #14
                            Hello @tmc_,

                            My mistake, I needed to included that. Post below edited.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Perfect! Thanks a lot for the help. This thread can be closed.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by RookieTrader, Today, 09:37 AM
                              3 responses
                              14 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by kulwinder73, Today, 10:31 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post kulwinder73  
                              Started by terofs, Yesterday, 04:18 PM
                              1 response
                              23 views
                              0 likes
                              Last Post terofs
                              by terofs
                               
                              Started by CommonWhale, Today, 09:55 AM
                              1 response
                              3 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by Gerik, Today, 09:40 AM
                              2 responses
                              7 views
                              0 likes
                              Last Post Gerik
                              by Gerik
                               
                              Working...
                              X