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

    #76
    I made a slight modification to the ChartTraderCustomButtonsExample indicator so that all four buttons are displayed in the lower section of the chart trader panel. It works fine until I load the indicator on multiple tabs. Once I load it on a second tab, the buttons on the first tab all move to the last row in the grid. Do you know what would cause this?
    Attached Files

    Comment


      #77
      Hello SystemTrading,

      The original does not appear to have this behavior with buttons added below the chart trader area.
      https://drive.google.com/file/d/1b4C...w?usp=drivesdk

      What modifications did you make?

      My guess would be that the incorrect grid row numbers are being used or possibly the buttons are being added to a different area.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #78
        I only changed lines 188-190 by replacing "chartTraderButtonsGrid" with "chartTraderGrid".

        Comment


          #79
          Hello SystemTrading,

          The original already places buttons in the chartTraderGrid. Changing this may have been unnecessary.
          The code from the original script on lines 188 to 190.
          Code:
          chartTraderGrid.RowDefinitions.Add(addedRow2);
          System.Windows.Controls.Grid.SetRow(lowerButtonsGrid, (chartTraderGrid.RowDefinitions.Count - 1));
          chartTraderGrid.Children.Add(lowerButtonsGrid);
          In your script, are you checking that there are not empty objects or rows being added unnecessarily and that the buttons are being removed from the correct location or object and that the rows are being removed properly?
          Chelsea B.NinjaTrader Customer Service

          Comment


            #80
            My mistake, I changed lines 181-185. The change was necessary to move the buttons below the default controls (see the attached images). Everything works properly until I load the indicator in a second tab.

            Comment


              #81
              Hello SystemTrading,

              My guess would be that they are not being removed from the correct place.

              The original script already places buttons there. Why not just use those and rename them and change the method?
              Chelsea B.NinjaTrader Customer Service

              Comment


                #82
                The original script places 2 buttons above the Instrument/TIF selector controls, and 2 buttons below the bid/ask labels. I'm trying to get all 4 buttons below the bid/ask labels, but I'm having this small issue.

                Comment


                  #83
                  Hello SystemTrading,

                  Are the buttons removed from the correct location?
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #84
                    Original Version:

                    Code:
                    public void InsertWPFControls()
                            {
                                if (panelActive)
                                    return;
                    
                                // add a new row (addedRow1) for upperButtonsGrid to the existing buttons grid
                                chartTraderButtonsGrid.RowDefinitions.Add(addedRow1);
                                // set our upper grid to that new panel
                                System.Windows.Controls.Grid.SetRow(upperButtonsGrid, (chartTraderButtonsGrid.RowDefinitions.Count - 1));
                                // and add it to the buttons grid
                                chartTraderButtonsGrid.Children.Add(upperButtonsGrid);
                    
                                // add a new row (addedRow2) for our lowerButtonsGrid below the ask and bid prices and pnl display            
                                chartTraderGrid.RowDefinitions.Add(addedRow2);
                                System.Windows.Controls.Grid.SetRow(lowerButtonsGrid, (chartTraderGrid.RowDefinitions.Count - 1));
                                chartTraderGrid.Children.Add(lowerButtonsGrid);
                    
                                panelActive = true;
                            }
                    
                    protected void RemoveWPFControls()
                            {
                                if (!panelActive)
                                    return;
                    
                                if (chartTraderButtonsGrid != null || upperButtonsGrid != null)
                                {
                                    chartTraderButtonsGrid.Children.Remove(upperButtonsGrid);
                                    chartTraderButtonsGrid.RowDefinitions.Remove(addedRow1);
                                }
                    
                                if (chartTraderButtonsGrid != null || lowerButtonsGrid != null)
                                {
                                    chartTraderGrid.Children.Remove(lowerButtonsGrid);
                                    chartTraderGrid.RowDefinitions.Remove(addedRow2);
                                }
                    
                                panelActive = false;
                            }
                    Modified Version:
                    Code:
                    public void InsertWPFControls()
                            {
                                if (panelActive)
                                    return;
                    
                                // add a new row (addedRow1) for upperButtonsGrid to the existing buttons grid
                                chartTraderGrid.RowDefinitions.Add(addedRow1);
                                // set our upper grid to that new panel
                                System.Windows.Controls.Grid.SetRow(upperButtonsGrid, (chartTraderGrid.RowDefinitions.Count - 1));
                                // and add it to the buttons grid
                                chartTraderGrid.Children.Add(upperButtonsGrid);
                    
                                // add a new row (addedRow2) for our lowerButtonsGrid below the ask and bid prices and pnl display            
                                chartTraderGrid.RowDefinitions.Add(addedRow2);
                                System.Windows.Controls.Grid.SetRow(lowerButtonsGrid, (chartTraderGrid.RowDefinitions.Count - 1));
                                chartTraderGrid.Children.Add(lowerButtonsGrid);
                    
                                panelActive = true;
                            }
                    
                    protected void RemoveWPFControls()
                            {
                                if (!panelActive)
                                    return;
                    
                                if (chartTraderGrid != null || upperButtonsGrid != null)
                                {
                                    chartTraderGrid.Children.Remove(upperButtonsGrid);
                                    chartTraderGrid.RowDefinitions.Remove(addedRow1);
                                }
                    
                                if (chartTraderGrid != null || lowerButtonsGrid != null)
                                {
                                    chartTraderGrid.Children.Remove(lowerButtonsGrid);
                                    chartTraderGrid.RowDefinitions.Remove(addedRow2);
                                }
                    
                                panelActive = false;
                            }

                    Comment


                      #85
                      Hello SystemTrading,

                      Is the grid row count back to the original value after all objects are removed?

                      Switching to a new tab should be removing all of the added objects and removing all added rows and all of the WPF should be reset back to the original state

                      If there is interference when another tab is opened, this is likely indicating that things are not being reset to the original state when changing tabs or removing the script.

                      If the script is reloaded several times, are the WPF controls added and removed from the correct location each time?
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #86
                        In the tab where the buttons display properly, the grid row count does go back to the original value after removing the rows. The row count in the non working tab shows extra rows until the indicator is reloaded. I can load the script multiple times in a single tab and the controls are added/removed in the correct location.

                        Comment


                          #87
                          Hello SystemTrading,

                          The issue is the row the buttons are being added to, correct?

                          Each time the tab is changed and then changed back a new row is added and the buttons are added to the new row, is this correct?

                          But the row count is correct?

                          Something is off there. I think if the buttons are being added to the wrong row, then that row is likely not being removed.

                          What is the row count before adding the buttons on a new chart (that hasn't been modified yet)?

                          What is the row count after the buttons are added the first time, and what is the row number the buttons are added to?

                          What is the row count after changing to a new tab and back, and what is the row number the buttons are added to?
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #88
                            I believe the issue is caused because two instances of the indicator are adding/removing controls from the chart trader panel. Everything works fine with multiple tabs if I only load one instance of the indicator. It shows 7 rows before adding the buttons, and 9 rows after adding the buttons. When I switch tabs and the controls are removed, it shows 9 rows before removing the buttons and 7 rows afterwards. When I load the indicator in another tab, one instance of the indicator works properly and shows the same row counts as mentioned. The other instance shows 9 rows before adding the buttons, and 11 rows afterwards. Similarly, it also shows 11 rows before removing the buttons, and 9 rows afterwards. I believe that the non-working instance is adding the controls to rows 10 and 11, and those rows are then being immediately removed by the working instance. As a result, all of the buttons end up in row 9.

                            Comment


                              #89
                              Hello SystemTrading,

                              The original script does not do this because it removes the added rows when a different tab is selected.

                              Give it a try. Open multiple tabs and add the original script to each tab so there are multiple instances but only one instance on each tab. Are you seeing the same behavior?

                              If opening an new tab and adding the indicator is causing the buttons to be added to incorrect rows, this would lead me to believe that when switching a way from that tab, the rows are not be removed correctly.
                              Chelsea B.NinjaTrader Customer Service

                              Comment


                                #90
                                The original script doesn't have the issue because it adds one row to the chartTraderGrid, and one row to the chartTraderButtonsGrid. If the original script is modified to add both rows to the chartTraderGrid, the issue occurs.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by warreng86, 11-10-2020, 02:04 PM
                                5 responses
                                1,356 views
                                0 likes
                                Last Post NinjaTrader_Manfred  
                                Started by Perr0Grande, Today, 08:16 PM
                                0 responses
                                3 views
                                0 likes
                                Last Post Perr0Grande  
                                Started by elderan, Today, 08:03 PM
                                0 responses
                                5 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
                                12 views
                                0 likes
                                Last Post maybeimnotrader  
                                Working...
                                X