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

Drawing on a chart from an Addon

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

    Drawing on a chart from an Addon

    Hi dear traders & coders;

    I'm currently developping an addon that should display technical analysis posted online.
    I have a first indicator that POST all the drawing object on a database, on a JSON format.

    The addon then retriew it an should draw it again to the chart.
    The problem is that the draws object is not drawed at all when I apply an analysis
    .

    Here you can find the part of the code that cause me issues

    Code:
       public IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
            {
                if (depObj != null)
                {
                    for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
                    {
                        DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
                        if (child != null && child is T)
                            yield return (T)child;
    
                        foreach (T childOfChild in FindVisualChildren<T>(child))
                            yield return childOfChild;
                    }
                }
            }
    
            public void ApplyAnalysis(Analysis analysis)
            {
                // Charts is a list of opened chart un the NinjaTrader session wich is automaticaly updated when a new chart is opened or destroyed
                bool finded = false;
                foreach (var window in this.Charts)
                {
                    window.Dispatcher.Invoke(new Action(() =>
                    {
                        foreach (ChartControl cc in FindVisualChildren<ChartControl>(window))
                        {
                            if (cc.Instrument.FullName == analysis.instrument)
                            {
                                finded = true;
                                DisplayAnalysis(cc, analysis);
                            }
                        }
                    }));
                }
    
                if(!finded)
                    MessageBox.Show($"Please open a chart of  {analysis.instrument} to apply the selected analysis");
            }
    
            private void DisplayAnalysis(ChartControl chart, Analysis analysis)
            {
                foreach (var draw in analysis.draws.Elements())
                {
                    var toDraw = DrawingTool.RestoreFromXElement(draw, false);
                    toDraw.CreateNewId();
    
                    chart.ChartObjects.Add(toDraw);
                    // may ViewModel is an IndicatorBase
                    DrawingTool.SetDrawingToolCommonValues(toDraw, toDraw.Tag, true, this, false);
                    toDraw.IsLocked = false;
                }
            }
    ​
    Does anyone faced the same type of issue? If yes, I'd be more than thankfull for your help

    #2
    Hello NeimadTWC,

    Drawing to a chart from an addon is not something that is supported by the normal NinjaScript api and its functions so whatever you come up with here would be a completely custom solution. I would not be able to provide any insight on this type of use case as you are using internal methods and drawing methods that are intended for drawing objects to use in their code to generate overloads for NinjaScript access from indicators or strategies.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Good day Jesse;

      Thanks for your answer. It's a bit weird that an opened platform as Ninja could be in term of coding doesn't allow it.
      BUT no issue then, I'll create an indicator that will communicate with the addon in a local websocket server

      Comment


        #4
        Correction.
        A single shared static class between the addon and an indicator does the trick.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Balage0922, Today, 07:38 AM
        0 responses
        3 views
        0 likes
        Last Post Balage0922  
        Started by JoMoon2024, Today, 06:56 AM
        0 responses
        6 views
        0 likes
        Last Post JoMoon2024  
        Started by Haiasi, 04-25-2024, 06:53 PM
        2 responses
        19 views
        0 likes
        Last Post Massinisa  
        Started by Creamers, Today, 05:32 AM
        0 responses
        6 views
        0 likes
        Last Post Creamers  
        Started by Segwin, 05-07-2018, 02:15 PM
        12 responses
        1,786 views
        0 likes
        Last Post Leafcutter  
        Working...
        X