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

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.
    Gaby V.NinjaTrader Customer Service

    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.
        Gaby V.NinjaTrader Customer Service

        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 AaronKoRn, Yesterday, 09:49 PM
          0 responses
          11 views
          0 likes
          Last Post AaronKoRn  
          Started by carnitron, Yesterday, 08:42 PM
          0 responses
          10 views
          0 likes
          Last Post carnitron  
          Started by strategist007, Yesterday, 07:51 PM
          0 responses
          11 views
          0 likes
          Last Post strategist007  
          Started by StockTrader88, 03-06-2021, 08:58 AM
          44 responses
          3,981 views
          3 likes
          Last Post jhudas88  
          Started by rbeckmann05, Yesterday, 06:48 PM
          0 responses
          9 views
          0 likes
          Last Post rbeckmann05  
          Working...
          X