Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

User interaction with drawing objects

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

    User interaction with drawing objects

    Hello,

    I would like to build an indicator that has some user interaction. Pretty simple, but not sure if it can be done easily (this is in part because there is no simple way to simply drop a line on a chart and have an alert on it breaking - feature suggestion - simple drop on chart line break alert! ). I would like the indicator to draw a horizontal line, but I want the user to be able to drag it up or down, like they could with a normal drawing object they added manually. I would like the indicator to be able to retrieve the current price level in onbarupdate for the alert.

    In testing, if I currently click on a horizontal line drawn by the indicator, I get the cannot move icon when I try to drag it. There does not seem to be a parameter in Draw.HorizontalLine to allow this?

    If possible, any pointers would be appreciated.

    #2
    Hello.

    Thanks for the post.

    You could use this indicator that labels manually drawn horizontal lines to build your idea. It reads all of the horizontal lines on the chart and labels them with their price.
    https://ninjatraderecosystem.com/user-app-share-download/labeled-horizontal-lines/

    Additional logic could be added to this to give alerts if the price breaks through the price of the line. You would need to work with OnRender for this task to get the price level information of the lines.

    To unlock a drawing tool after it has been drawn by a NinjaScript, set it's IsLocked property to false right after drawing it.

    Code:
    HorizontalLine myLine = Draw.HorizontalLine(this, "tag1", Close[0], Brushes.Red);
    myLine.IsLocked = false;
    EX:
    Code:
     public class LabeledHorizLineAutoAlert : Indicator
    {
    public struct LineInfo
    {
    public string lineTag;
    public double linePrice;
    public bool lineGreaterThan;
    public bool lineTriggered;
    }
                    public double storePriceforOBU;
            ....
    
            protected override void OnRender(ChartControl chartControl, ChartScale
            chartScale)
    {
    base.OnRender(chartControl, chartScale);
                            ...
                            foreach (Gui.NinjaScript.IChartObject thisObject in ChartPanel.ChartObjects)
      {
    
     if(thisObject is NinjaTrader.NinjaScript.DrawingTools.HorizontalLine)
     {
    
    
      HorizontalLine myline = thisObject as NinjaTrader.NinjaScript.DrawingTools.HorizontalLine;
                                     storePriceForOBU = myline.StartAnchor.Price
                                     ...
    Here is the documentation to the OnRender method:
    https://ninjatrader.com/support/help.../?onrender.htm

    Please let us know if we may be of any further assistance.
    Last edited by NinjaTrader_ChrisL; 03-27-2023, 03:09 PM.

    Comment


      #3
      Hello Chris... Do you have a working example or a more detailed explanation of how to recognize a breakout of a drawing tool? In my case, I want to identify breakouts of user-drawn trend channels. I assume the indicator you have referred to is the "LabeledHorizontalLines" indicator. Thank you

      An example video of what I want to achieve is found here on minute 19:18 and onward: https://youtu.be/zdVg2fiXuB4
      .
      Last edited by rperez; 03-26-2023, 04:58 PM.

      Comment


        #4
        Hi rperez, Unfortunately I do not have any other examples that come to mind. The example I linked in this post from 2018 shows how to read and identify specific lines on the chart. This idea can be used to find any kind of drawing object.

        Comment


          #5
          Hi Chris, Can you please confirm if the indicator you referred to is the "LabeledHorizontalLines" indicator? I ask because the link you put (http://www.ninjatrader.com/support/f...d=7&linkid=991​) sent me to the NTEcosystem and doe not point to any indicator in particular.

          Thanks again,

          Rperez

          Comment


            #6
            Hi, I am referring to the LabeledHorizontalLine indicator here:

            This indicator will read the horizontal lines that you have applied to a chart and display the price at which that line sits.


            I have also fixed the link above.

            Comment


              #7
              Hi Chris, Thanks, that´s the one I thought about. Now, looking into the example code it seems to allow the user to move the horizontal line that was drawn within the ninja script. What I need is different. If the user draws a line and hovers it above the price, and if at any given price there was an action to be taken if the price breached the line, then a message appears or a bar color change takes place. For a better explanation of my need please watch a couple of minutes from this video, starting at about min 17:30. https://www.youtube.com/watch?v=zdVg2fiXuB4

              I will appreciate your suggestions as to how to achieve this

              Rperez

              Comment


                #8
                Hi, thanks for the follow-up. Unfortunately, I do not know of any existing examples that will show you the exact code to accomplish this. It will take a lot of code to write an indicator that will do this and it's a multi-faceted problem to solve, from drawing and identifying the lines that are drawn (already exemplified in my example above) to monitoring price action against that horizontal line price value, which should be done in OnBarUpdate with the indicator running OnEachTick, to coloring the bar using BarBrushes. The two pieces that are missing here are keeping the line's price data updated and using that price data to compare and create price action conditions in OnBarUpdate and changing the bar color based on those conditions.

                Comment


                  #9
                  Hi Chirs, Thank you for taking the time to consider my request.

                  RPerez

                  Comment


                    #10
                    Hi Chris, I have written an indicator based on your code.

                    This indicator has 2 parts:

                    Part 1: draws a global horizontal line with a specific tag,
                    Part 2: searches for the line. Can you advise how can I search it by its tag?



                    PHP Code:
                            protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
                            {
                                  
                                        
                                try
                                {
                                    base.OnRender(chartControl, chartScale);
                    
                    
                                    foreach (Gui.NinjaScript.IChartObject thisObject in ChartPanel.ChartObjects)
                                      {
                                          if(thisObject is NinjaTrader.NinjaScript.DrawingTools.HorizontalLine
                    
                                             // && How do I search the line by tag?
                    
                                                
                                            )
                                          {
                                               HL                   = thisObject as NinjaTrader.NinjaScript.DrawingTools.HorizontalLine;
                                                
                                               HLValueByRender      = HL.StartAnchor.Price;
                        
                                          }
                                      }
                    ​ 
                    
                    Last edited by Rainmakersg; 06-25-2024, 01:47 AM.

                    Comment


                      #11
                      Hello,

                      Thank you for your post.

                      Since you already have the object, you can just use the tag.

                      Print(HL.Tag);



                      Please let us know if you have any further questions.

                      Comment


                        #12
                        Hi Gaby, if there are many horizontal lines that are manually drawn by the chart, I wish to identify the specific horizontal line that is drawn by the indicator. This horizontal line has a specific tag. How do I search for it in my code above?

                        Comment


                          #13
                          Hello,

                          If you are trying to access manually drawn lines, or lines drawn by another indicator, you can loop through the DrawObjects collection.

                          The Help Guide page below has code demonstrating:

                          Comment


                            #14
                            Hi Gaby, please take a moment to read what I am asking.

                            I am running the search loop under OnRender, not OnBarUpdate. Because I am using thisObject instead of draw in the search loop, I don't see anyway to add tag to the search, unlike for draw, which has draw.Tag.

                            Comment


                              #15
                              Hello,

                              I did not say you needed to use OnBarUpdate(). You can still access the DrawObjects collection and loop through it in OnRender().

                              If you are trying to access manually drawn objects on a chart through code, the only way to do it would be to access them via the DrawObjects collection.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              557 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              324 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              101 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              545 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              547 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X