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 ms52390, 06-20-2024, 03:48 PM
        2 responses
        14 views
        0 likes
        Last Post ms52390
        by ms52390
         
        Started by ccrone2024, Today, 05:13 AM
        0 responses
        7 views
        0 likes
        Last Post ccrone2024  
        Started by ttodua, Today, 03:40 AM
        0 responses
        6 views
        0 likes
        Last Post ttodua
        by ttodua
         
        Started by ttodua, Today, 03:18 AM
        0 responses
        7 views
        0 likes
        Last Post ttodua
        by ttodua
         
        Started by TraderKnG, Today, 01:30 AM
        0 responses
        13 views
        0 likes
        Last Post TraderKnG  
        Working...
        X