Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

check if draw object exists

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

    check if draw object exists

    is there a way to see if a draw object exits. I don't need to look I want to see if it exists by tag name

    #2
    Hello ballboy11,

    Thanks for the note.

    There exists the DrawObjects[] collection to get all of the draw objects applied to the chart:

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

    That is a good way to find a drawing object by tag name.

    Alternatively, please see this example where I loop through all of the drawing objects on the chart by searching through the ChartPanel.ChartObjects collection on line 154 in OnRender(). This example finds the draw object by its type.

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


    Please let us know if we may be of any further assistance.
    Last edited by NinjaTrader_ChrisL; 05-15-2019, 08:22 AM.

    Comment


      #3
      Chris, can you correct that 2nd link? i cant find which code you refer

      Comment


        #4
        Hi TazoTodua, Thanks, the link has been updated.

        Comment


          #5
          Hello,

          from the link with looping to find specific draw object I got help for what I need and I use as name for the drawingobjects the price where it is drawn so that I can refer later to this drawobject by price. But I work round many hours and can´t fix one problem: how can one work with the tagname/price to compare with current price like if(High[0]>"drawobjectname/tagname/price") then Remove(....) If High[0]> ???

          Thank you!
          Tony

          Comment


            #6
            Hello Tony,

            You can reference a Drawing object by name with DrawObjects["YOURTAG"] and you can access the Anchors of the Drawing Object to see where it is drawn.
            From there you could use the tag with RemoveDrawObject to remove that object from the chart.

            Below is an example showing how to access Anchors of a DrawObject.

            Code:
            if (DrawObjects["Dot"] != null)
            {
                foreach (ChartAnchor anchor in DrawObjects["Dot"].Anchors)
                    Print(anchor.Price);
            }
            We look forward to assisting.

            Comment


              #7
              Hi,

              I have created a simple indicator to detect a horizontal line. The original value of the line is set to 1000. When a line is drawn or moved, the anchor price of the horizontal is shown and updated. However, when I delete the line, how do I get it to reset to 1000? Thanks your assistance. Code below.

              public class HorizontalLineDetector : Indicator
              {

              // Declare variables
              HorizontalLine HL;
              private double HLValue = 1000 ;



              protected override void OnStateChange()
              {
              if (State == State.SetDefaults)
              {
              Description = @"Enter the description for your new custom Indicator here.";
              Name = "HorizontalLineDetector";
              Calculate = Calculate.OnBarClose;
              IsOverlay = true;
              DisplayInDataBox = false;
              DrawOnPricePanel = true;
              DrawHorizontalGridLines = true;
              DrawVerticalGridLines = true;
              PaintPriceMarkers = false;
              ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
              //Disable this property if your indicator requires custom values that cumulate with each new market data event.
              //See Help Guide for additional information.
              IsSuspendedWhileInactive = true;
              }
              else if (State == State.Configure)
              {
              }
              }

              protected override void OnBarUpdate()
              {
              //Add your custom indicator logic here.
              }

              protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
              {

              foreach (Gui.NinjaScript.IChartObject thisObject in ChartPanel.ChartObjects)
              {

              if(thisObject is NinjaTrader.NinjaScript.DrawingTools.HorizontalLin e)
              {
              HL = thisObject as NinjaTrader.NinjaScript.DrawingTools.HorizontalLin e;
              HLValue = HL.StartAnchor.Price;
              }
              }

              Print ("HLValue : ");
              Print (HLValue);

              }




              }


              My code is highlighted in purple. I just copied and pasted here. I would also appreciate it if you could share with me the way to share a code so it shows up as properly formatted as above post #6.

              Comment


                #8
                Hello Rainmakersg,

                You can reset the variable before entering the loop. If the line is found, the variable will be updated to the line's anchor. If the line is not found, the variable will remain at the initial value.

                Comment


                  #9
                  Hi Jim, thanks so much

                  Can you share how to paste a code so it is properly formatted like in post #6 above?

                  Comment


                    #10
                    Hello Rainmakersg,

                    There is an issue with the VBulletin forum that we use that affects formatting code when we paste in.

                    I typically copy snippets and paste them in a [CODE] block, and then I press the space bar to format the code nicely.

                    Comment


                      #11
                      Hi Jim, you mean you use the space bar to space out the tabs line by line?

                      Comment


                        #12
                        Yes, when I paste onto a forum message, the formatting is lost, and I use the space bar to format the code I post after I paste it in [CODE] blocks.

                        Comment


                          #13
                          Thanks Jim. It's so tedious...

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          566 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          330 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
                          547 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          548 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X