Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

same indicator across multiple tabs but for different instruments

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

    same indicator across multiple tabs but for different instruments

    the following code I am using to detect if an indicator is set to a chart tab and that it is applied to that tab

    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 Gui.Chart.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 Gui.Chart.ChartTab;
                if (chartTab == null)
                    return;
    
    
                if (TabSelected())
                {
                    //RemoveWPFControls();
                    InsertWPFControls();
                }
                else
                {
                    RemoveWPFControls();
                }
            }​
    However, if the same indicator is applied to another tab but a different instrument it seems as though the indicator is functioning off of the first tab applied indicator -

    is there a way to apply the same indicator to multiple tabs and have them function with the data for the seperate tabs?

    #2
    Hello WHICKED,

    Thank you for your post.

    For a functioning example of an indicator that makes WPF modifications and uses the data for separate tabs, please see the SampleWPFModifications example here:For that indicator, in OnBarUpdate() it finds the lowOfTheDay and draws that value with Draw.TextFixed() as follows:

    Code:
            protected override void OnBarUpdate() {
    
                // Get the current date
                DateTime currentDate = Time[0].Date;
                lowOfTheDay = CurrentDayOHL().CurrentLow[0];
                var currentPrice = Close[0];
               // Check if the current bar's date matches today's date
               if (Time[0].Date == currentDate)
               {
                    var diff = currentPrice - lowOfTheDay;
                    Draw.TextFixed(this, "PositionSize", lowOfTheDay+ "%0.12R: " + (int)(12/diff) , TextPosition.TopLeft, Brushes.Green, new SimpleFont("Arial", 25), Brushes.Transparent, Brushes.Transparent, 100);                    
               }
            }​
    If you apply this indicator to multiple tabs and toggle between tabs, you will see that the low value changes to match the input series for the indicator applied to that tab. I suggest reviewing TabSelected() and TabChangedHandler() to see if there are differences between that sample and your own. You could test making some changes to see what the results are. It may also be helpful to add different print statements throughout your script to understand what values are being used and where it might be getting the incorrect/unexpected value. This will help to hone in on what part of your logic may need to be adjusted. For more details on using prints and debugging scripts:Please let us know if we may be of further assistance.

    Comment


      #3
      what about if you are adding buttons to the top portion of the chart or on the side - is there a way to handle that linking?

      Comment


        #4
        Hello WHICKED,

        Thank you for your reply.

        I am not sure that I follow your question. What "linking" are you referring to? For example, if you open a chart with two tabs and apply the Sample WPF Modifications indicator to only one of the tabs, there are extra buttons added to the top, sides, and chart trader for that tab. If you toggle to the other open tab that does not have the indicator applied, the buttons do not appear on that tab. If this does not address your question, please provide an example or explain with additional details so I may better understand and assist you.

        Please feel free to reach out with any additional questions or concerns.

        Comment


          #5
          Originally posted by NinjaTrader_Emily View Post
          Hello WHICKED,

          Thank you for your reply.

          I am not sure that I follow your question. What "linking" are you referring to? For example, if you open a chart with two tabs and apply the Sample WPF Modifications indicator to only one of the tabs, there are extra buttons added to the top, sides, and chart trader for that tab. If you toggle to the other open tab that does not have the indicator applied, the buttons do not appear on that tab. If this does not address your question, please provide an example or explain with additional details so I may better understand and assist you.

          Please feel free to reach out with any additional questions or concerns.
          From that example code - you place one row of buttons below the price/contract count dialog - how would you place multiple rows/colums below the trade buttons so that when you tab between charts if the indicator is applied to that chart it will retain the same positioning etc, but will change the visual information based on which chart you are tabbed to?

          Comment


            #6
            Hello WHICKED,

            Thank you for your reply.

            If you apply an indicator to a chart, it will only be able to process data based on the input data series selected in the indicator settings or any added data series from calling AddDataSeries() programmatically. The SampleWPFModifications will only show the added buttons for chart tabs that have the indicator applied. If you want to add buttons to multiple tabs and have the "visual information" based on the chart you are tabbed to, I suspect you mean information displayed on the buttons based on the instrument in the tab. This means you will need to add the indicator to each tab separately. Each separate instance of the indicator will be able to calculate based on the input series, such as the instrument shown on that tab. If you open a new tab and do not add the indicator, the buttons will not be added. To have the buttons shown and change the information based on the instrument for that tab, you must add the indicator to that tab.

            The SampleWPFModifications contains helpful code comments throughout explaining what different portions of code are used for such as the following, for example:
            Code:
                    // Runs ShowWPFControls if this is the selected chart tab, other wise runs HideWPFControls()
                    private void TabChangedHandler(object sender, SelectionChangedEventArgs e)
                    {
                        if (e.AddedItems.Count <= 0)
                            return;
            
                        tabItem = e.AddedItems[0] as TabItem;
                        if (tabItem == null)
                            return;
            
                        chartTab = tabItem.Content as ChartTab;
                        if (chartTab == null)
                            return;
            
                        if (TabSelected())
                            ShowWPFControls();
                        else
                            HideWPFControls();
                    }​
            I suggest studying the example and reviewing the code comments to get more information about how it behaves in regard to using multiple chart tabs.

            Please let us know if we may be of further assistance.

            Comment


              #7
              Modifying the code to try to add an additional row below the lowerButtonsGrid section - if you apply the indicator to one tab and apply to the second tab - if you tab between them you can see that the Button 6 will get moved in to one line with the other buttons that were in the top row.

              Is that expected behavior? that on tab changing that the buttons would get squashed together?

              Attaching modifications:
              Attached Files

              Comment


                #8
                Hello WHICKED,

                Thank you for your reply.

                I was unable to import your attachment to test it on multiple tabs and observe what you are describing. Please be sure to export the script via the Control Center > Tools > Export > NinjaScript AddOn function and attach the .zip file that is generated here so that the export is in the proper format to import without errors.

                I appreciate your patience and look forward to your reply.

                Comment


                  #9
                  attaching exported indicator......
                  Attached Files

                  Comment


                    #10
                    Hello WHICKED,

                    Thank you for your reply.

                    I suspect the behavior has to do with the region starting at line 485 "Use case #5: Custom chart trader buttons wpf objects"
                    It seems there is another grid, lowerButtonsGrid2, and buttons are potentially being added there. Ultimately, the WPF controls within your script are not NinjaScript-specific and have to do with general WPF .NET Framework knowledge. If you have questions about NinjaTrader-specific methods and properties, we are able to assist, otherwise you will potentially need to refer to outside resources and debugging to resolve any issues with the WPF/general C# portions of your logic.

                    More information regarding WPF controls may be found at the following publicly available link:
                    This article introduces WPF controls, detailing their creation, styling, templating, events, and rich content support via XAML or code.


                    The links to C# documentation from the page for the reference sample may also be helpful:


                    Thank you for your time and patience.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    637 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    366 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    107 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    569 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    571 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X