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 vitalpilot, Yesterday, 11:14 PM
      1 response
      3 views
      0 likes
      Last Post ezrollin  
      Started by PaulMohn, 09-15-2021, 05:25 AM
      21 responses
      106 views
      0 likes
      Last Post omololu
      by omololu
       
      Started by mcosta72, Yesterday, 04:09 PM
      0 responses
      17 views
      1 like
      Last Post mcosta72  
      Started by Quanto, Yesterday, 02:50 PM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_ChrisL  
      Started by Trader108, Yesterday, 01:45 PM
      2 responses
      16 views
      0 likes
      Last Post Trader108  
      Working...
      X