Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to communicate between Addon and Indicator

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

    How to communicate between Addon and Indicator

    Hi,

    I'd like to be able to have an Addon call a function in my Indicator on a specific chart.

    Picture this. I have an Indicator that has a function that draws a vertical line at the current bar. However this function gets called all it does is draw a line at the current bar. I have an Addon that has a window with a single button. I want to push that button and somehow have it call the function in the Indicator to draw the vertical line. Obviously, the Addon needs to know which chart is the active one with focus because I don't want the line on every chart.

    It would also be nice if the Indicator could communicate back to the Addon that it drew the line.

    Is this possible? If it is, then this is a great starting point for me to continue my Addon idea.

    Thanks,
    Fred

    #2
    Hello PhineasPhred,

    Thank you for your post.

    It sounds like you could likely use a shared variable that can be accessed by both the addon and the indicator. You could monitor the value of the variable from both scripts. When the button is pressed, change the variable - the indicator could then check the variable, see that it has changed, and draw your line accordingly.

    Here's a link to another forum post that has an example of shared methods and variables:

    https://ninjatrader.com/support/foru...956#post733956

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hi Kate,

      That might work. I found another post for Collector/Subscriber that might work better...if there's a way for the indicator to know if the chart is in focus or active.

      Is there an api for this? If so, then I could broadcast to all the subscribed indicators and then let each indicator determine if it's the one the user is looking at.

      Here's the link to the Collector/Subscriber post:

      https://ninjatrader.com/support/foru...isk-management

      Comment


        #4
        Hello PhineasPhred,

        Thank you for your reply.

        Those examples are essentially doing exactly what I've recommended, creating public variables that may be accessed by both scripts. It's the same concept.

        However it's gonna get extremely tricky if you're clicking on a button in the add-on to draw a line in a particular instance of the indicator, since clicking the button in the addon would remove the focus from the chart if it's in a different window. You could add the indicator to all charts and loop through all charts and programmatically access that indicator to tell it to draw on the chart through public methods, but if you want to pick a specific window, you'd likely be unable to do so since checking for focus wouldn't be plausible.

        Here's an example of looping through to find chart 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;
        
        // make sure the found chart is the owner window
        if (foundChart != this.Owner as NinjaTrader.Gui.Chart.Chart) return;
        }));
        }
        What I'd suggest is instead of putting the button that controls this into a separate add on, that you consider instead making the button part of the indicator since the user would have to apply the indicator to each chart it's to be used on anyway.

        Here's an example from our UserAppShare that could be adapted to your button functionality:

        https://ninjatraderecosystem.com/use...bar-buttons-2/

        Please let us know if we may be of further assistance to you.

        The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Hi Kate,

          Thanks for the reply. All good points. When I made my original post I was trying to keep it simple. But the real Addon will add the buttons to a panel next to ChartTrader on every chart. So, I'm assuming the focus issue won't be a problem. Right now I'm checking using a TabSelected generic function to determine if the chart has focus. I didn't see another way of doing this. Is this correct?

          I originally built this as an indicator, but my ultimate goal was to have it as an addon (to do the UI stuff) and an indicator (to do the order/account stuff) and have the addon install the indicator itself for every chart created. In a previous post you and I discussed having the addon do just that and you submitted a feature request, SFT-1445, for that feature. I'm working forward with that in mind.

          If you build it as an installable addon then the user never has to worry about adding it to his charts. It kind of becomes part of NinjaTrader.

          Comment


            #6
            Hello PhineasPhred,

            Thank you for your reply.

            The feature request process is generally very slow and there are large numbers of requests that don't get added to the platform. All requests are evaluated by our development team for a number of factors and they have the final say on whether a feature request is granted. I would advise that you operate under the assumption that it won't be added in the near future.

            That being said, if you're adding buttons from an addon, it's going to be difficult to draw on the chart from the indicator. If you want to draw on the chart, you will still need an indicator that is added to the chart so you can tell it to draw on the chart, so it would be best to add buttons from the indicator, and add the indicator to each chart.

            You could also create a default chart template that includes this indicator so it would just be automatically added when new charts are created to eliminate some of that issue.

            Please let us know if we may be of further assistance to you.

            Kate W.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by POTTER16, Today, 03:31 PM
            0 responses
            8 views
            0 likes
            Last Post POTTER16  
            Started by enricbcn, 05-08-2018, 01:36 AM
            78 responses
            43,521 views
            1 like
            Last Post Wessel
            by Wessel
             
            Started by Wessel, Today, 12:50 PM
            0 responses
            8 views
            0 likes
            Last Post Wessel
            by Wessel
             
            Started by asmmbillah, Today, 12:39 PM
            0 responses
            9 views
            0 likes
            Last Post asmmbillah  
            Started by dtmtradingco, Today, 12:30 PM
            0 responses
            7 views
            0 likes
            Last Post dtmtradingco  
            Working...
            X