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 carnitron, Today, 08:42 PM
      0 responses
      2 views
      0 likes
      Last Post carnitron  
      Started by strategist007, Today, 07:51 PM
      0 responses
      4 views
      0 likes
      Last Post strategist007  
      Started by StockTrader88, 03-06-2021, 08:58 AM
      44 responses
      3,969 views
      3 likes
      Last Post jhudas88  
      Started by rbeckmann05, Today, 06:48 PM
      0 responses
      5 views
      0 likes
      Last Post rbeckmann05  
      Started by rhyminkevin, Today, 04:58 PM
      4 responses
      58 views
      0 likes
      Last Post dp8282
      by dp8282
       
      Working...
      X