Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Send Reference From Inidcators ChartControl to AddOn

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

    Send Reference From Inidcators ChartControl to AddOn

    Hello,

    I created an Indicator that adds a button to the toolbar to open an AddoOn window, and it has a few methods.

    I then created an AddOn that creates a window with WPF controls.

    Ideally I'd like to have the window call the methods on the indicator but cant keep a reference to it due to the "calling thread cannot access this object because a different thread owns it" error.

    So secondly I would like the Window to use the ChartControl and ChartBars that the indicator is on but don't know what class and namespace they are in.

    #2
    Hello richt3,

    Thank you for your post.

    Please see this forum post which has a script example of an approach you can use:



    The first sample passes an instance of the indicator to the AddOn, and the AddOn calls indicator properties.

    For your use case, if you need to do something with the dispatcher it would be best to program a public method in the indicator that references whichever indicator properties are needed. Then, call the method from the AddOn.

    Please let us know if you have any further questions.

    Comment


      #3
      Thanks Gaby!

      I went back and researched a bit more and found my issue is in the method I call (successfully) back on the indicator. I have a line:

      ChartControl.ChartPanels[0].Focus();

      That's where I get the "calling thread cannot access this object because a different thread owns it" exception. Does that have to be wrapped or something?

      Comment


        #4
        Hello richt3,

        Are you checking if you access to the thread or using a dispatcher? Please see this Help Guide page which has a code snippet and goes into more detail:

        https://ninjatrader.com/support/helpGuides/nt8/multi-threading.htm

        Please let me know if I can assist further.
        Last edited by NinjaTrader_Gaby; 02-16-2024, 01:49 PM.

        Comment


          #5
          Perfecto!

          For future reference I changed:

          ChartControl.ChartPanels[0].Focus();
          // then remaiinng method code....

          To:

          ChartControl.Dispatcher.InvokeAsync(new Action(() => {
          ChartControl.ChartPanels[0].Focus();​
          // remainder of method code needs to go here as it is an async call...
          }));​

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          633 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          364 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          105 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          567 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          568 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X