• 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 babouin77, Yesterday, 08:37 PM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_PaulH  
                              Started by tomd0361, Yesterday, 08:58 PM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_PaulH  
                              Started by Talicer, Today, 05:40 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post Talicer
                              by Talicer
                               
                              Started by PG7940, Today, 04:36 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post PG7940
                              by PG7940
                               
                              Started by elliot5, Today, 03:40 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post elliot5
                              by elliot5
                               
                              Working...
                              X