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

Through ADD ON, Access/Get Specific Chart Window (out of several open chart windows)

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

    Through ADD ON, Access/Get Specific Chart Window (out of several open chart windows)

    Hi,

    While developing an NT8 ADDON, I have come across a bottleneck and to get out of this, I seek experts help. In OnWindowCreated(), I check whether the new window is a chart. If yes, I add a button to the chart. Then on button click I use GetWindow Function to get a sort of reference/pointer to the chart and do some modifications with the objects on the chart (for example add or delete custom buttons). The same thing explained here can also be viewed in short code I have attached below.

    The problem starts when I open a second chart. Now, OnWindowCreated(), myChart and myChart1 in the code below both point towards the second chart and if I click the button on the first chart, I get errors like the object is owned by another thread and cannot be accessed.

    My need is that on button click, I can get reference/pointer to the chart window from which the button was pressed and do modifications in the objects on that particular chart.
    It's probably possible with one or a few lines of code but I got stuck here and could not develop that despite huge efforts. Will be thankful if an expert can get me out of this.
    The related piece of code is given below.

    Gui.Chart.Chart myChart, myChart1, chartWindow;
    protected override void OnWindowCreated(Window window)
    {
    myChart = window as Gui.Chart.Chart;
    if (myChart == null)
    return;
    myChart1 = myChart;
    sampleButton = new Button
    {
    Content = " PSC ",
    Style = System.Windows.Application.Current.TryFindResource ("Button") as Style
    };
    myChart.MainMenu.Add(sampleButton);
    sampleButton.Click += SampleButton_Click;
    System.Windows.Automation.AutomationProperties.Set AutomationId(sampleButton, "SampleButton");
    }

    private void SampleButton_Click(object sender, RoutedEventArgs e)
    {
    chartWindow = System.Windows.Window.GetWindow(myChart1.ActiveCha rtControl.Parent) as Gui.Chart.Chart;
    }


    #2
    Hi Mubeen, thanks for writing in.

    Tapping into chart objects is not an officially supported feature so support for this will be limited. There is an existing example here that adds buttons to the SuperDOM:

    https://ninjatraderecosystem.com/use...s-to-superdom/

    Notice that the "AddButtonsMethod" is called using a dispatcher, and the variables are local to the method only (no class level properties such as Gui.Chart.Chart myChart, myChart1, chartWindow)

    See also this example that loops through the workspace and gets every open ChartControl object, it might be helpful:
    https://ninjatrader.com/support/foru...ons#post837439

    Since this is more of a WPF/C# related issue, I will unfortunately not be able to research any further into the WPF/C# topics.

    Kind regards,
    -ChrisL

    The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by helpwanted, Today, 03:06 AM
    0 responses
    3 views
    0 likes
    Last Post helpwanted  
    Started by Brevo, Today, 01:45 AM
    0 responses
    6 views
    0 likes
    Last Post Brevo
    by Brevo
     
    Started by aussugardefender, Today, 01:07 AM
    0 responses
    5 views
    0 likes
    Last Post aussugardefender  
    Started by pvincent, 06-23-2022, 12:53 PM
    14 responses
    242 views
    0 likes
    Last Post Nyman
    by Nyman
     
    Started by TraderG23, 12-08-2023, 07:56 AM
    9 responses
    384 views
    1 like
    Last Post Gavini
    by Gavini
     
    Working...
    X