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

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.
    Chris L.NinjaTrader Customer Service

    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.
        Chris L.NinjaTrader Customer Service

        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.
            Chris L.NinjaTrader Customer Service

            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.
                Chris L.NinjaTrader Customer Service

                Comment


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

                  RPerez

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by TraderBCL, Today, 04:38 AM
                  2 responses
                  7 views
                  0 likes
                  Last Post TraderBCL  
                  Started by martin70, 03-24-2023, 04:58 AM
                  14 responses
                  105 views
                  0 likes
                  Last Post martin70  
                  Started by Radano, 06-10-2021, 01:40 AM
                  19 responses
                  606 views
                  0 likes
                  Last Post Radano
                  by Radano
                   
                  Started by KenneGaray, Today, 03:48 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post KenneGaray  
                  Started by thanajo, 05-04-2021, 02:11 AM
                  4 responses
                  471 views
                  0 likes
                  Last Post tradingnasdaqprueba  
                  Working...
                  X