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

Can Addon Distinguish Between Two Charts

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

    Can Addon Distinguish Between Two Charts

    If I open two identical charts is there a way for an addon to know which chart is which? Do charts have an ID or some unique identifying parameter that can be queried by an addon to know which chart its working on?

    If not, is there a tag or some user parameter that we can set with an addon to ID the chart when it first opens?

    I don't want to use an indicator to do this and I want to assume that everything about the two charts is identical, same time frame, same instrument, etc, except for this identification parameter.

    Thanks,
    Fred

    #2
    Hello PhineasPhred,

    Thanks for your question.

    We are starting to get into undocumented territory, but you may wish to access ChartControl.OwnerChart.GetHashCode() to get an integer that can be used as an identifier. This can be called from an indicator. If you would like to get a hash code externally, you consider checking the following in a loop through all windows.

    Code:
    foreach (var window in NinjaTrader.Core.Globals.AllWindows)
    {
        // check if the found window is a Chart window, if not continue looking
        if (!(window is NinjaTrader.Gui.Chart.Chart)) continue;
    
        window.Dispatcher.InvokeAsync(new Action(() =>
        {
            // try to cast as a Chart, if it fails it will be null
            var foundChart = window as NinjaTrader.Gui.Chart.Chart;
    
            // make sure we found a chart
            if (foundChart == null) return;
    
            Print(foundChart.GetHashCode());
    
        }));
    
    }
    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hi Jim,

      I actually thought about using GetHashCode() at one time, but wasn't sure if it was guaranteed to be unique for each chart, especially if both charts were the same. I'm assuming from your answer that I can rest assured.

      Thanks for the quick response and help!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by bortz, 11-06-2023, 08:04 AM
      47 responses
      1,605 views
      0 likes
      Last Post aligator  
      Started by jaybedreamin, Today, 05:56 PM
      0 responses
      8 views
      0 likes
      Last Post jaybedreamin  
      Started by DJ888, 04-16-2024, 06:09 PM
      6 responses
      18 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by Jon17, Today, 04:33 PM
      0 responses
      4 views
      0 likes
      Last Post Jon17
      by Jon17
       
      Started by Javierw.ok, Today, 04:12 PM
      0 responses
      13 views
      0 likes
      Last Post Javierw.ok  
      Working...
      X