• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

can`t detect manually brushed rectangle

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

    can`t detect manually brushed rectangle

    Hi
    I can`t detect manually brushed rectangle by this code:

    foreach(IDrawingTool myDrawObject in DrawObjects) {
    DrawingTools.Rectangle myRectangle = myDrawObject as DrawingTools.Rectangle;
    if (null != myRectangle) Print("Found a rectangle");
    }

    How can i detect it and get prices and times of rectangle?

    #2
    Hello Dert66,

    Thanks for your post and welcome to the NinjaTrader forums!

    Here is a simple example of how to check for draw objects:

    Code:
     foreach (DrawingTool draw in DrawObjects.ToList())
                  {
                    Print (draw.Tag+"  "+draw.Description+" "+draw.DisplayName+" "+draw.Id+"  "+draw.MaxValue+"  "+draw.MinValue);
                }
    You can expand the print example to check the bool state of draw.IsUserDrawn.

    The help guide provides further examples of detecting and changing draw objects here: https://ninjatrader.com/support/help...rawobjects.htm

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thank you! But how can i get prices and times of rectangle?

      Comment


        #4
        Hello Dert66 ,

        Thanks for your post.

        Here is an example:

        Code:
                    foreach (DrawingTool draw in DrawObjects.ToList())
                      {
                        if (draw is DrawingTools.Rectangle && draw.IsUserDrawn)
                        {                    
                            DrawingTools.Rectangle mycopy = draw as DrawingTools.Rectangle;
        
                            Print (mycopy.Tag+"  "+mycopy.StartAnchor.Time+"  "+mycopy.StartAnchor.Price+"  "+mycopy.EndAnchor.Time + "  " + mycopy.EndAnchor.Price);
                        }
                    }
        The start and end anchor properties can be found here: https://ninjatrader.com/support/help...rawingtool.htm
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          This condition does not work:
          if (draw is DrawingTools.Rectangle)
          Ninjatrader Ver: 8.0.18.1 64-bit
          please, help me

          Comment


            #6
            Hello Dert66,

            Thanks for your reply.

            You are conditionally looking for rectangles on Bar 515, if you remove that condition does your code then work?

            Paul H.NinjaTrader Customer Service

            Comment


              #7
              No.........

              Comment


                #8
                Hello Dert66,

                Thanks for your reply.

                I've created a short video demonstrating working code here: https://Paul-ninjaTrader.tinytake.co...Ml8xMTEwNjQ4MQ

                I suspect that if you drew a new rectangle that it would be detected, otherwise I would suggest adding the && draw.IsUserDrawn as shown in my code.

                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Thank you, Paul H!!
                  after "reload all historical data" - its OK!

                  Comment


                    #10
                    for the condition to work I have to re-draw the rectangles
                    if(draw is DrawingTools.Rectangle && draw.IsUserDrawn){}
                    how to detect rectangles drawn before adding an indicator?

                    Comment


                      #11
                      Hello Dert66,

                      Thanks for your reply.

                      With reference back to the code/indicator have shown, if added to a chart with existing rectangles, on each OnBarUpdate, the existing rectangles are found and any new one drawn after it is added as well.

                      I am not sure i understand what you mean by, "how to detect rectangles drawn before adding an indicator?"
                      Paul H.NinjaTrader Customer Service

                      Comment


                        #12
                        No this condition:
                        Code:
                        foreach(DrawingTool draw in DrawObjects.ToList()) {
                        if(draw is DrawingTools.Rectangle && draw.IsUserDrawn){Print("detect rect");}
                        }
                        detect rectangles only if indicator are loaded before I drawing rectangles
                        but
                        This code:
                        Code:
                        foreach(DrawingTool draw in DrawObjects.ToList()) {
                        if (draw.Name == "Rectangle" && draw.IsUserDrawn) {
                             foreach(ChartAnchor myAnchor in draw.Anchors) {
                                             Print("Rect_ancor"+myAnchor);
                            }
                        }
                        detect ancors of rectangle
                        if indicator are loaded before AND After I drawing rectangles

                        Comment


                          #13
                          Hello Dert66,

                          Thanks for your reply.

                          Looks like you have a solution for your needs.
                          Paul H.NinjaTrader Customer Service

                          Comment


                            #14
                            How can I get color for my
                            draw
                            object
                            Code:
                            foreach(DrawingTool draw in DrawObjects.ToList()) { if (draw.Name == "Rectangle" && draw.IsUserDrawn) { foreach(ChartAnchor myAnchor in draw.Anchors) { Print("Rect_ancor"+myAnchor); } }

                            Comment


                              #15
                              Hello Dert66,

                              Thanks for your reply.

                              With reference to post #4 mycopy.AreaBrush, mycopy.Outlinestroke.Brush
                              Paul H.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Newtrader101, Today, 03:54 PM
                              1 response
                              15 views
                              0 likes
                              Last Post NinjaTrader_ShawnB  
                              Started by williamzz, Today, 03:28 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post williamzz  
                              Started by Robert87, Today, 11:07 AM
                              0 responses
                              14 views
                              0 likes
                              Last Post Robert87  
                              Started by phta123, Today, 10:24 AM
                              0 responses
                              17 views
                              0 likes
                              Last Post phta123
                              by phta123
                               
                              Started by sidviciousX, Today, 06:47 AM
                              0 responses
                              16 views
                              0 likes
                              Last Post sidviciousX  
                              Working...
                              X