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

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
    JimNinjaTrader Customer Service

    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.
          JimNinjaTrader Customer Service

          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.
                JimNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by mjairg, 07-20-2023, 11:57 PM
                3 responses
                213 views
                1 like
                Last Post PaulMohn  
                Started by TheWhiteDragon, 01-21-2019, 12:44 PM
                4 responses
                544 views
                0 likes
                Last Post PaulMohn  
                Started by GLFX005, Today, 03:23 AM
                0 responses
                3 views
                0 likes
                Last Post GLFX005
                by GLFX005
                 
                Started by XXtrader, Yesterday, 11:30 PM
                2 responses
                12 views
                0 likes
                Last Post XXtrader  
                Started by Waxavi, Today, 02:10 AM
                0 responses
                7 views
                0 likes
                Last Post Waxavi
                by Waxavi
                 
                Working...
                X