Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to change the text of Chart Trader buttons in NT7 & NT8?

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

    How to change the text of Chart Trader buttons in NT7 & NT8?

    Hello,

    How can I change the 'Buy Market' text/string of the Chart Trader 'Buy Market' Button.

    I need to use Autohotkey search text macros with multiple Chart Trader Windows and thus need custom/unique string values.

    #2
    Hello Cormick,

    Thank you for your post.

    You could change the Buy Market button text in Chart Trader using WPF modifications. Please see Case #6 in the attached ModifiedSampleWPFModificationsExample script which demonstrates how you could use WPF modifications to change the Buy Market button text in Chart Trader.

    In the example script, chartTraderGrid.FindFirst("ChartTraderControlQuick BuyMarketButton") as Button; is used to get the Buy Market button. Once you have the button you are able to change the contents of the button. Please see line 936 in the SampleWPFModifications example which demonstrates setting the text of the Buy Market button to "Custom Buy Market".

    Please let us know if we may assist further.
    Attached Files
    Last edited by NinjaTrader_BrandonH; 07-20-2021, 02:28 PM.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Hi Brandon,
      I've detected that in use case #6, the content/text of the button is not removed and consequently, all new charts also display the "Custom Buy Mkt" text.
      I've made a small modification to add an image as content of the button and obviously I have the same issue of all new charts getting by default the image associated to the Buy Mkt button in the Charttrader panel.

      if (modifyCtBuyMarketButton != null)
      {
      modifyCtBuyMarketButton.Click += ModifyCtButton_Click;
      modifyCtBuyMarketButton.Background = Brushes.Green;
      modifyCtBuyMarketButton.Content = new Image
      {
      Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(NinjaTrader.Core.Globals.UserDataDir + @"bin\Custom\AddOns\buypower.png")),
      VerticalAlignment = VerticalAlignment.Center,
      Height = 40,
      Width = 40
      };
      }


      I guess I should initially get the content by default of the Buy Mkt button and introduce modifications in the DisposeWPFControls()/HideWPFControls() section but have no clue of how to do it.

      Thanks in advance,
      M

      Comment


        #4
        Hello motog4berria,

        Thanks for your note.

        The SampleWPFModification script linked in my previous post is an outdated version of the example script.

        Please see the SampleWPFModification script in post #139 in this forum thread for an up-to-date version of the example script. In the updated version, there is an example of using an image in a button.

        Hello All, Moving forward this will be maintained in the help guide reference samples and no longer maintained on the forum. Creating Chart WPF (UI) Modifications from an Indicator - https://ninjatrader.com/support/help...ui)-modifi.htm (https://ninjatrader.com/support/helpGuides/nt8/creating-chart-wpf-(ui)-modifi.htm) I've


        Let us know if we may assist further.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Hi Brandon,
          that's not what I was asking for. I only want the "Custom Buy Mkt" label that is applied to the Buy Mkt button -when using the original indicator version of the present thread- to be removed when a new tab is opened. In the new indicator version you cite, there is no new label associated to the Buy Mkt button and therefore my question has not been answered. How do I remove said added label from the use case #6 of the version in the current thread (or an image I introduce as content for the button as detailed in my previous post)?
          Thanks,
          M

          Comment


            #6
            Hello motog4berria,

            Thanks for your note.

            Are you referring to the text in a button? This would be considered the button content (<Button>.Content).

            If so, see line 517 of the SampleWPFModifications script for an example of setting the Content for a Button.

            Also, see this publicly available Microsoft documentation on System.Windows.Control.Button for information about working with buttons: https://docs.microsoft.com/en-us/dot...ontrols.button

            Let us know if we may assist further.
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              Hi Brandon,

              -"Are you referring to the text in a button? This would be considered the button content (<Button>.Content)."
              Yes, that should be clear from my messages. See my first post above where I also introduce an image as content (instead of the modified text).

              -"If so, see line 517 of the SampleWPFModifications script for an example of setting the Content for a Button."
              But that button is NOT the default Buy Mkt button but one introduced with all its content (use case#5). In siad use case #5, the disposal of the added buttons is straightforward:
              if (chartTraderButtonsGrid != null || upperButtonsGrid != null)
              {
              chartTraderButtonsGrid.Children.Remove(upperButton sGrid);
              chartTraderButtonsGrid.RowDefinitions.Remove(custo mCtaddedRow1);
              }

              However, said logic cannot be used with a predefined button since no rows/grids are added.

              As said in my previous post, I only want a small modification to use case#6 in order to customize the layout of NT Chartpanel default buttons.

              The indicator initially gets the background of the default/original buttons in private void LoadBrushesFromSkin() (see attachment) and sets background and content of default/original Buy/Sell Mkt buttons with specific text&color. Then in disposewpf controls section, a reference is made to HideWPFControls() where background is set to the original (see HideWPFControls image) but some lines of code are missing to revert the content introduced via the ShowWPFControls() (see attachment) to the default "Buy/Sell Mkt" content.

              It makes no sense that you share an indicator covering WPF buttons modifications and from a version to the next, interesting use case#6 is modified and no answer is provided to a problem detected in the original indicator version (current post).

              If you don't want to guide me to find the solution or do not have time, say so, but pls do not refer me to publicly available information I already have.

              Thanks,
              M
              Last edited by motog4berria; 07-20-2021, 11:07 AM.

              Comment


                #8
                attachments here
                Attached Files

                Comment


                  #9
                  Hello M,

                  I'd like to simplify and clarify the specific objective. You are wanting to remove the text on an exiting button in ChartTrader, is this correct?

                  If so, Brandon is giving the correct advice. The text in the button is the .Content property of the button. You can set this to an empty string.
                  Line 517 in the file is showing the Content property of a button being set. This can also be set for existing buttons similar to how the Background of a button can be set shown on line 940.
                  Grid rows and columns are not involved with setting the .Content of a button.

                  If our understanding is incorrect, in that you are not trying to remove the text from an existing ChartTrader button, may we have you clarify your objective?
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello M,

                    I'd like to simplify and clarify the specific objective. You are wanting to remove the text on an exiting button in ChartTrader, is this correct?

                    If so, Brandon is giving the correct advice. The text in the button is the .Content property of the button. You can set this to an empty string. You can set this to an image.
                    Line 517 in the file is showing the Content property of a button being set. This can also be set for existing buttons similar to how the Background of a button can be set shown on line 940.

                    An example of setting an image (within an optional stack panel) to a button content is shown on lines 249 to 264.

                    Grid rows and columns are not involved with setting the .Content of a button.



                    If our understanding is incorrect, in that you are not trying to remove the text from an existing ChartTrader button, or set an image within an existing button, may we have you clarify your objective?
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Chelsea,
                      your understanding is incorrect. Let me be more graphical (see attached tab1 and tab2 images) since my best efforts are not good enough as implied by your answers:
                      1- In tab 1, when I apply your indicator, a customized button with "Custom Buy Market" text and green background is displayed instead of the default "Buy Mkt" button.
                      2- When I open a new tab and load an empty chart, the default Buy Mkt button gets the text/label of the firt tab (no disposal of the custom content).

                      - "You are wanting to remove the text on an exiting button in ChartTrader, is this correct?"
                      I want to remove the text added to the default Buy Mkt button when I open a new chart/tab.

                      As Brandon, you are referring me to a totally different use case where all info of the buttons is directly entered.
                      Thanks,
                      M
                      Attached Files

                      Comment


                        #12
                        Hello M,

                        I am likely still not understanding. Your screenshot is showing the Buy Market button with the text "Custom buy Ma". This would imply that you are trying to set the text of a button, but you have said this is not what you want to do.

                        Can you say in a few words specifically what you would like to achieve?

                        Where you have stated:
                        In tab 1, when I apply your indicator, a customized button with "Custom Buy Market" text and green background is displayed instead of the default "Buy Mkt" button.
                        This would not be the SampleWPFModifications indicator linked below. The Buy Market button does not have the text changed from this example indicator. You may have a modified version. Please re-download the original linked below. The example does however, set the background color on line 940.
                        https://ninjatrader.com/support/foru...07#post1124507

                        It doesn't matter if it's a new button or an existing button. You can can set the Content. Line 517 shows setting the Content to string.Format("Button {0}", i + 1), but this can be any string you would like. The same Content property would be set on an existing button so this would be an example of setting the Content.
                        Try adding a line below line 90 and setting the modifyCtBuyMarketButton.Content to "" or string.Empty. This would remove the default text of the Buy Market button.
                        Last edited by NinjaTrader_ChelseaB; 07-20-2021, 12:32 PM.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi Chelsea,
                          why are you linking an indicator? Why not starting by reading the whole thread? I'm always referring to the indicator in the current thread, pls check the second entry above (see message #2).

                          -"Try adding a line below line 90 and setting the modifyCtBuyMarketButton.Content to "" or string.Empty. This would remove the default text of the Buy Market button."

                          I already tried -before starting to post- your empty string solution to check if the default text is overwritten by an empty string or not. That, as expected, generates a button with no text (see tab3 image) when a new chart/tab is open. Obviously I also tried the reintroduction of the original text (by using modifyCtBuyMarketButton.Content="Buy/Sell Mkt") of the buttons of the Chartpanel but that is far from optimal.

                          Wouldn't it be possible to obtain the default text/content of the default buttons and apply them in the Dispose/Hide..() in a manner similar to the default background of the buttons:

                          private void LoadBrushesFromSkin()
                          {
                          // while pulling brushes from a skin to use later in the chart,
                          // sometimes we need to be in the thread of the chart when the brush is initialized

                          #region CommonResources
                          [...]

                          #region Use case #6: Modify existing chart trader buttons initialize variables

                          ctOriginalButtonBrush = Application.Current.TryFindResource("ChartTrader.B uttonBackground") as LinearGradientBrush ?? new LinearGradientBrush(Brushes.Purple.Color, Brushes.Pink.Color, 1);
                          #endregion
                          }


                          with the followingn Dispose/HideWPFCOntrols:

                          private void HideWPFControls()
                          {
                          [...]
                          #region Use case #6: Modify existing chart trader buttons hide controls
                          // if this instance of the script has added event handlers and changed colors, then set everything back to original state
                          if (modifyCtButtonsActive)
                          {
                          // when the tab is selected or the indicator is removed, reset the colors and remove the added click handler
                          if (modifyCtBuyMarketButton != null)
                          {
                          modifyCtBuyMarketButton.Click -= ModifyCtButton_Click;
                          modifyCtBuyMarketButton.Background = ctOriginalButtonBrush;
                          // modifyCtBuyMarketButton.Content = "Buy Mkt";
                          }

                          if (modifyCtSellMarketButton != null)
                          {
                          modifyCtSellMarketButton.Click -= ModifyCtButton_Click;
                          modifyCtSellMarketButton.Background = ctOriginalButtonBrush;

                          // modifyCtBuyMarketButton.Content = "Sell Mkt";
                          }

                          Button foundButton = chartTraderButtonsGrid.FindFirst("ctOriginalButton Info") as Button;
                          if (foundButton != null)
                          chartTraderButtonsGrid.Children.Remove(foundButton );

                          modifyCtButtonsActive = false;
                          }
                          #endregion



                          Thanks,
                          M
                          Attached Files

                          Comment


                            #14
                            Hello motog4berria,

                            I am linking the original SampleWPFModifications script that I have created. The file in post #2 appears to be a modified version.

                            Where you have stated:
                            already tried -before starting to post- your empty string solution to check if the default text is overwritten by an empty string or not.
                            I am not suggesting any checks...
                            You previously stated:
                            I want to remove the text added to the default Buy Mkt button when I open a new chart/tab.
                            I was understanding this as you want to remove the text.
                            Setting the Content to an empty string would remove the text.

                            To clarify and simplify once more, are you wanting to save the text of button to a variable so that you can set this to a button later?
                            Last edited by NinjaTrader_ChelseaB; 07-20-2021, 02:11 PM.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Not directly related to the question, but it might help viewers with custom buttons needs:

                              Tick Hunter Bot / Assistant from the User Apps Share, by excellent RFrosty
                              Last edited by Cormick; 07-21-2021, 05:02 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by elderan, Today, 08:03 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post elderan
                              by elderan
                               
                              Started by algospoke, Today, 06:40 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post algospoke  
                              Started by maybeimnotrader, Today, 05:46 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post maybeimnotrader  
                              Started by quantismo, Today, 05:13 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post quantismo  
                              Started by AttiM, 02-14-2024, 05:20 PM
                              8 responses
                              169 views
                              0 likes
                              Last Post jeronymite  
                              Working...
                              X