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

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:
                            [LEFT][COLOR=#252C2F][FONT=Courier][SIZE=12px]foreach(DrawingTool draw in DrawObjects.ToList()) {
                            if (draw.Name == "Rectangle" && draw.IsUserDrawn) {
                                 foreach(ChartAnchor myAnchor in draw.Anchors) {
                                                 Print("Rect_ancor"+myAnchor);
                                }
                            }[/SIZE][/FONT][/COLOR][/LEFT]

                            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 Jon17, Today, 04:33 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post Jon17
                              by Jon17
                               
                              Started by Javierw.ok, Today, 04:12 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post Javierw.ok  
                              Started by timmbbo, Today, 08:59 AM
                              2 responses
                              10 views
                              0 likes
                              Last Post bltdavid  
                              Started by alifarahani, Today, 09:40 AM
                              6 responses
                              41 views
                              0 likes
                              Last Post alifarahani  
                              Started by Waxavi, Today, 02:10 AM
                              1 response
                              21 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Working...
                              X