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

Modifications to chart WPF elements and tab considerations

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

    Hello Mindset,

    I was suggesting that you add rows to the lowerButtonsGrid..

    System.Windows.Controls.Grid.SetColumn() sets which column the button will appear in.

    On line 142, this will set the second button to the 3rd column (the 2nd column is a spacing column).

    Code:
    System.Windows.Controls.Grid.SetColumn(buttonsArray[1], 2);
    Last edited by NinjaTrader_ChelseaB; 09-28-2020, 09:57 AM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      Originally posted by kkc2015 View Post
      Hi Unsuitable,
      Are you just looking for functional buttons on the edge of the chart screen? Please see attached chart screen.
      If so, I could provide you with related codes, which are all from Ninjatrader samples.

      [ATTACH]n1118752[/ATTACH]
      Yes that would be great!
      Unsuitable
      NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

      Comment


        Hi Unsuitable,
        Attached is a file showing the grid and button codes that I used in my application, which are also functional with tabbed charts. Note that all of the codes are from samples provided by Ninjatrader.
        Attached Files

        Comment


          kkc2015

          Your code doesn't compile FYI.

          Comment


            Hi Unsuitable,
            Sorry for the confusion. The file contains the codes for the buttons and the grids + other unrelated variables which were used for other indicators. It is not a complete stand alone indicator and contains other variables (with declaration deleted) and thus would not compile. The main purpose is to show 1) the frame work, 2) the actual codes for the buttons and grids and 3) where they should be placed.

            You have to copy and paste only the button and grid codes, including declarations, and placed in the same sections (eg. initialize inside State.SetDefaults, State.DataLoaded, etc) of your indicator.

            Comment


              Hello kkc2015,

              To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
              1. Click Tools -> Export -> NinjaScript...
              2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
              3. Click the 'Export' button
              4. Enter a unique name for the file in the value for 'File name:'
              5. Choose a save location -> click Save
              6. Click OK to clear the export location message
              By default your exported file will be in the following location:
              • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
              Below is a link to the help guide on Exporting NinjaScripts.
              http://ninjatrader.com/support/helpG...-us/export.htm
              Chelsea B.NinjaTrader Customer Service

              Comment


                //
                Originally posted by kkc2015 View Post
                Hi Unsuitable,
                Sorry for the confusion. The file contains the codes for the buttons and the grids + other unrelated variables which were used for other indicators. It is not a complete stand alone indicator and contains other variables (with declaration deleted) and thus would not compile. The main purpose is to show 1) the frame work, 2) the actual codes for the buttons and grids and 3) where they should be placed.

                You have to copy and paste only the button and grid codes, including declarations, and placed in the same sections (eg. initialize inside State.SetDefaults, State.DataLoaded, etc) of your indicator.
                Yeah no worries mate, I went with another button solution.

                So this dispatcher thing is new to me, but it's a requirement and what not for buttons. In the OG code, it went through each individual button by name. For 2 buttons this solution is fine, however for 10+ buttons, repeating the same code over and over is just bad practice. Down below I've implemented a for loop that takes care of all the buttons. Does this check out? It does compile but there can be some run time errors as well.

                Code:
                ChartControl.Dispatcher.InvokeAsync((() =>
                {
                    if (myGrid != null)
                    {
                      System.Windows.Controls.Button[] buttons = { Button1, Button2, Button3, Button4, Button5, Button6, Button7, Button8, Button9, Button10};
                
                      for (int i = 0; i < buttons.Count(); i++)
                      {
                         if (buttons[i] != null)
                         {
                            myGrid.Children.Remove(buttons[i]);
                            buttons[i].Click -= OnMyButtonClick;
                            buttons[i] = null;
                         }
                      }
                
                   // if (Button1 != null)
                   // {
                   //    myGrid.Children.Remove(Button1);
                   //    Button1.Click -= OnMyButtonClick;
                   //    Button1 = null;
                   // }
                    }
                }));
                Thanks

                Edit: It must work cause if I remove that piece of code, it starts duplicating the buttons.
                Last edited by Unsuitable; 09-29-2020, 02:29 PM.
                Unsuitable
                NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

                Comment


                  Hi Unsuitable,
                  It looks like you are making good progress.
                  Attached are a screen shot and a totally stripped down version of a button indicator (NT8), which can be imported and compiled.
                  If you press the Help button to make it green, when you press any other buttons, you can see the text on the bottom right of the chart, showing the pressed button. After you have loaded this indicator on the chart, you will see the column of buttons on the right side of the chart.
                  Good luck.
                  Attached Files
                  Last edited by kkc2015; 10-02-2020, 11:19 AM.

                  Comment


                    Hi kkc2015,

                    I started to move the buttons so that they are alongside the main menu buttons. However, the solution to programmatically remove all the buttons does not seem to work with the main menu buttons. So chartWindow.MainMenu is where all the buttons are stored. When it comes to NT natives buttons, it has a wrapper and within that wrapper, there are the NT buttons. So the only object buttons within chartWindow.MainMenu[] are my buttons.

                    Solutions tried
                    1. Creating a new list and at the time of creating the buttons, store the new buttons. RESULT: the indicator crashes
                    2. Tried using the UserControlCollection. RESULT: NT doesn't catch the crash so it infinite loops and I have to recover NT
                    3. Using a foreach loop and specifying button filter. RESULT: indicator crashes
                    4. Using a foreach loop and specifying Object filter and printing the elements: RESULT: Buttons + NinjaTrader.Gui.Tools.InstrumentSelector NinjaTrader.Gui.Tools.IntervalSelector + etc

                    Code:
                    ChartControl.Dispatcher.InvokeAsync((() =>
                    {
                      if (chartWindow != null)
                      {
                        //System.Windows.Controls.Button[] buttonsChartControl = {exampleButton}; //hardcoded
                        //System.Windows.Controls.Button[] buttonsChartControl = chartWindow.MainMenu.OfType<System.Windows.Control s.Button>().ToArray(); //programmatically
                    
                        foreach (System.Windows.Controls.Button btn in chartWindow.MainMenu)
                        {
                          Print(btn.ToString());
                        }
                    
                        System.Windows.Controls.Button[] buttonsChartControl = buttonList.ToArray();
                    
                        Print("ss");
                        for (int i = 0; i < buttonsChartControl.Count(); i++)
                        {
                          Print("test ");
                          if (buttonsChartControl[i] != null)
                          {
                            Print("bob ");
                            chartWindow.MainMenu.Remove(buttonsChartControl[i]);
                            buttonsChartControl[i].Click -= OnMyButtonClick;
                            buttonsChartControl[i] = null;
                            buttonList.Remove(buttonsChartControl[i]);
                          }
                        }
                      }
                    }));
                    HOLD YOUR HORSES, I got it. Solution 1 does work, however one needs to initialize it. So it went from this

                    Code:
                    private List<System.Windows.Controls.Button> buttonList;
                    to
                    Code:
                    private List<System.Windows.Controls.Button> buttonList;
                    ...
                    buttonList = new List<System.Windows.Controls.Button>();
                    Last edited by Unsuitable; 09-29-2020, 08:13 PM. Reason: Clicked reply instead of preview
                    Unsuitable
                    NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

                    Comment


                      All right Unsuitable, it looks like you have solved the problem.

                      Comment


                        Hi Unsuitable would be interested to see your final result. The tool bar you had in NT7 is exactly what I'm looking for in NT8. I've tried to code something myself but I'm only a beginner coder.
                        thanks in advance.

                        Comment


                          Originally posted by rcrook23 View Post
                          Hi Unsuitable would be interested to see your final result. The toolbar you had in NT7 is exactly what I'm looking for in NT8. I've tried to code something myself but I'm only a beginner coder.
                          thanks in advance.
                          There are no exact NT7 to NT8 toolbars conversions.
                          NT7 Toolbar: https://ninjatraderecosystem.com/use...lbar-shortcut/

                          However, people have used other libraries to reproduce the same functionality;
                          https://ninjatraderecosystem.com/use...njaaddons-com/
                          https://ninjatraderecosystem.com/use...-mahtoolbar-2/

                          *Do note mahtoolbar calls the DrawingTool by way of hotkeys. So you may have to modify the script to match your hotkeys or use NT defaults.
                          Last edited by Unsuitable; 10-01-2020, 03:21 PM.
                          Unsuitable
                          NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

                          Comment


                            Originally posted by kkc2015 View Post
                            Hi Unsuitable,
                            It looks like you are making good progress.
                            Attached are a screen shot and a totally stripped down version of a button indicator (NT8), which can be imported and compiled.
                            If you press the Help button to make it green, when you press any other buttons, you can see the text on the bottom right of the chart, showing the pressed button. After you have loaded this indicator on the chart, you will see the column of buttons on the right side of the chart.
                            Good luck.
                            Hi kkc2015. Thanks for sharing.
                            I'm getting this when trying to download the code:
                            Invalid File Specified


                            Could you please re-up the file?
                            Thanks a lot.

                            Comment


                              Hi Dougtre,
                              Try these files.
                              Attached Files

                              Comment


                                Originally posted by kkc2015 View Post
                                Hi Dougtre,
                                Try these files.
                                Thanks a lot!

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Javierw.ok, Today, 04:12 PM
                                0 responses
                                4 views
                                0 likes
                                Last Post Javierw.ok  
                                Started by timmbbo, Today, 08:59 AM
                                2 responses
                                10 views
                                0 likes
                                Last Post bltdavid  
                                Started by alifarahani, Today, 09:40 AM
                                6 responses
                                40 views
                                0 likes
                                Last Post alifarahani  
                                Started by Waxavi, Today, 02:10 AM
                                1 response
                                18 views
                                0 likes
                                Last Post NinjaTrader_LuisH  
                                Started by Kaledus, Today, 01:29 PM
                                5 responses
                                15 views
                                0 likes
                                Last Post NinjaTrader_Jesse  
                                Working...
                                X