Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Working with Indicators and Draw Objects in a Strategy's Chart.

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

    Working with Indicators and Draw Objects in a Strategy's Chart.

    I'm attempting to get multiple indicators to show on the same panel in a chart with Strategy on it.

    I also would like to add some horizontal lines to these panels. None of this seems to be possible without writing a custom indicator to combine all these features into one Indicator.

    I referenced https://ninjatrader.com/support/help...us/?editor.htm about changing the panel assigned to an indicator once it was added in State.DataLoaded. This seems to indicate I could move an indicator to a different panel once it's added with AddChartIndicator().

    Similarly, Draw objects have an overload that has the bool parameter drawOnPricePanel, but in a Strategy there is no way to specify which panel to draw on.

    Looking forward to ideas on how to get around this.
    daqu40
    NinjaTrader Ecosystem Vendor - QTradez

    #2
    Hello daqu40,

    Thanks for your post.

    Your understanding is correct regarding how to add indicators to different panels. A hosting indicator can be built, or the panel can be modified when using AddChartIndicator. Changing the panel would only be applicable for indicators that use IsOverlay = true. IsOverlay = false will add the indicator to a new panel.

    To specify different panels to draw on, you could place your Draw calls in your strategy and specify the indicator that owns the panel for the "NinjaScript" parameter of the Draw method. I've attached an example.

    I look forward to being of further assistance.
    Attached Files

    Comment


      #3
      Thanks Jim!

      That is exactly what I'm looking for.

      I'd like to easily get a few indicators in the same panel, but the draw objects in the proper indicator panel are more critical.
      daqu40
      NinjaTrader Ecosystem Vendor - QTradez

      Comment


        #4
        Hi Jim,

        I found this article useful.

        I have now been able to plot lines to represent stops and targets for a pairs trade. However, my strategy is in control of the lines.

        Is it possible to manually move these lines? Or, as an alternative can the strategy detect lines manually placed on the panel and read the price / values.

        Thanks,

        Ian

        Comment


          #5
          Hello Ianc28,

          Thanks for your question.

          NinjaScript drawn lines can be unlocked in order to have the user modify them after they have been placed.

          Code:
          NinjaTrader.NinjaScript.DrawingTools.Line myLine = Draw.Line(this, "tag1", false, 10, 1000, 0, 1001, Brushes.LimeGreen, DashStyleHelper.Dot, 2);
          myLine.IsLocked = false;
          If you want to find drawing objects on the chart that are either user drawn or drawn from another script, you could access the chart's DrawObjects collection.

          DrawObjects - https://ninjatrader.com/support/help...rawobjects.htm

          Please let us know if we can be of further assistance.

          Comment


            #6
            Hi Jim,

            Thanks for the above info. All seems good.

            I am still struggling to get the startY and endY values out of the drawing object.

            Thanks

            Ian

            I

            Comment


              #7
              It OK Jim I found it.

              Thanks

              Ian

              Comment


                #8
                Hello IanC28,

                You can get the Price and Time of the drawn object through the object's Start and End Anchors. Time can be converted to a bar index, and then to a BarsAgo index using CurrentBar and ChartBars.GetBarIdxByTime().

                Code:
                // An alternative approach to find the draw object by a tag
                if (DrawObjects["ThisLine"] as DrawingTools.Line != null && DrawObjects["ThisLine"].GetType().Name == "Line")
                {
                    DrawingTools.Line foundLine = DrawObjects["ThisLine"] as DrawingTools.Line;
                
                    ClearOutputWindow();
                    Print(foundLine.StartAnchor.Price);
                    Print(foundLine.StartAnchor.Time);
                    Print(foundLine.EndAnchor.Price);
                    Print(foundLine.EndAnchor.Time);
                
                    Print("Index of Start Anchor: " + ChartBars.GetBarIdxByTime(ChartControl, foundLine.StartAnchor.Time));    
                    Print("Index of End Anchor: " + ChartBars.GetBarIdxByTime(ChartControl, foundLine.EndAnchor.Time));
                    Print("BarsAgo of Start Anchor: " + (CurrentBar - ChartBars.GetBarIdxByTime(ChartControl, foundLine.StartAnchor.Time)));    
                    Print("BarsAgo of End Anchor: " + (CurrentBar - ChartBars.GetBarIdxByTime(ChartControl, foundLine.EndAnchor.Time)));    
                }
                Line object documentation - https://ninjatrader.com/support/helpGuides/nt8/line.htm

                ChartBars.GetBarIdxByTime - https://ninjatrader.com/support/help...ridxbytime.htm

                Please let us know if we can be of further assistance.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Yesterday, 05:17 AM
                0 responses
                62 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                134 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                75 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                45 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                50 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X