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

How I can get Rectangle coordinates.

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

    How I can get Rectangle coordinates.

    Hello!
    How I can get Rectangle coordinates.
    Code:
        protected override void OnBarUpdate()
            {
                foreach (DrawingTool draw in DrawObjects.ToList()) // Iterate over all objects
                {
                    if (draw is DrawingTools.Line)//Here is Truly working
                    {               
                        // Indicates line Tag
                        Print("Find Line Object: " + draw.Tag);
                      }    
    
                    if (draw is DrawingTools.Rectangle)//<-I need here choose object rectangle. Why not working this line?
                    {               
                        // Indicates rectangle Tag
                        Print("Find Rectangle Object: " + draw.Tag);
    
                     //How I can get coordinates or Rectangle. I need rectangle coordinates.
                      double startY; //Start Y Value of Rectangle
                      double endY;  //End Y Value of Rectangle
                      double startDateTime; //Start Y Value of Rectangle
                      double endDateTime; //End Y Value of Rectangle
    
                     //Thank You Very Much
                      }    
                }
            }
    Line:
    if (draw is DrawingTools.Line)//Here is Truly working
    Is working Perfect.
    Why not working line:
    if (draw is DrawingTools.Rectangle)//<-I need here choose object rectangle. Why not working this line?
    How I can get Rectangle coordinates.
    On the chart I have a plot same objects.
    Thank You Very Much.

    #2
    Hello _Roman,

    Thanks for your post and welcome to the NinjaTrader Forums!

    Here is a short example you can test with:

    protected override void OnBarUpdate()
    {
    if (State != State.Realtime) return; // waits until real time connected then finds rectangle (only did for this test)

    if (DrawObjects.Count > 0) // Make sure we have an objects first
    {
    foreach (DrawingTool draw in DrawObjects.ToList()) // Go through objects
    {
    if (draw is DrawingTools.Rectangle) // test to find rectangle
    {
    Print ("Tag name: "+draw.Tag); // priint tag name
    DrawingTools.Rectangle temp = draw as DrawingTools.Rectangle; // create copy to get anchorpoints

    Print("startY: " + temp.StartAnchor.Price);
    Print("startX: " + temp.StartAnchor.Time);

    Print("endY: " + temp.EndAnchor.Price);
    Print("endX: " + temp.EndAnchor.Time);
    }
    }
    }
    }


    Example screesnhot:

    Click image for larger version

Name:	Roman-1.PNG
Views:	590
Size:	32.0 KB
ID:	1053718
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Click image for larger version

Name:	356-101-rozovaja-roza-ot-rosemarktru.jpg
Views:	430
Size:	171.7 KB
ID:	1053724
      Thank You Very Much my Dear NinjaTrader_PaulH
      When I will check Your method I will surely unsubscribe. Let me check. Thanks a lot.

      Comment


        #4
        The method is realy working. Thank you Very Much. You may close the Topic. The issue has fully resolved. Thank you Very Much.

        Comment


          #5
          Originally posted by NinjaTrader_PaulH View Post
          Hello _Roman,

          Thanks for your post and welcome to the NinjaTrader Forums!

          Here is a short example you can test with:

          protected override void OnBarUpdate()
          {
          if (State != State.Realtime) return; // waits until real time connected then finds rectangle (only did for this test)

          if (DrawObjects.Count > 0) // Make sure we have an objects first
          {
          foreach (DrawingTool draw in DrawObjects.ToList()) // Go through objects
          {
          if (draw is DrawingTools.Rectangle) // test to find rectangle
          {
          Print ("Tag name: "+draw.Tag); // priint tag name
          DrawingTools.Rectangle temp = draw as DrawingTools.Rectangle; // create copy to get anchorpoints

          Print("startY: " + temp.StartAnchor.Price);
          Print("startX: " + temp.StartAnchor.Time);

          Print("endY: " + temp.EndAnchor.Price);
          Print("endX: " + temp.EndAnchor.Time);
          }
          }
          }
          }


          Example screesnhot:

          Click image for larger version

Name:	Roman-1.PNG
Views:	590
Size:	32.0 KB
ID:	1053718


          Hello Paul, I tried this code and works perfect when I draw a rectangle in chart, but it is not working when an indicator draw this rectangle.

          Any suggestion?

          Thanks

          Comment


            #6
            Hello federicoo,

            Thanks for your post.

            I tested here with an indicator that draws (Yellow) rectangles and ran the code (that draws a red test rectangle) and was able to pick up all of the details for each rectangle.

            Please see attached.


            Click image for larger version

Name:	fredericoo-2.PNG
Views:	493
Size:	68.0 KB
ID:	1099226

            You might want to double click on the indicators rectangles to look in the drawing objects properties to see if there is any info that may be helpful.
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Thank you Paul,

              Please see the screenshot attached. May be the drawing type is not a rectangle. Could I retrieve with coding which is the drawing type of the ones made by the indicator from the chart?

              BR
              Attached Files

              Comment


                #8
                Hello federicoo,

                Thanks for your reply.

                You might try:


                foreach (DrawingTool draw in DrawObjects.ToList())
                {
                Print ("Tag: "+draw.Tag+" Descr: "+draw.Description+" DisplayName: "+draw.DisplayName+" ID#: "+draw.Id
                +" MAXValue: "+draw.MaxValue+" MinValue: "+draw.MinValue+" UsrDrawn? ");
                }
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Here is the output:

                  Tag: @RectArb_35 25,53 Descr: DisplayName: Rectangle ID#: d5059f32e1d541aa87112b193f032829 MAXValue: -1,79769313486232E+308 MinValue: 1,79769313486232E+308 UsrDrawn?

                  Thanks

                  Comment


                    #10
                    The code is failing in this sentence:

                    if (draw is DrawingTools.Rectangle) // test to find rectangle

                    This sentence is never true, it is like there were not any Rectangle in chart.

                    Thanks

                    Comment


                      #11
                      And the rare thing here is that the drawing is described as a Rectangle using the script of post #8 in chart.

                      Comment


                        #12
                        Hello federicoo,

                        Thanks for your replies.

                        I've tried to replicate your condition by drawing a global rectangle and running the code to obtain the rectangle values and have no problems in doing so.

                        Can you provide further information on what is drawing the rectangle in question?

                        Paul H.NinjaTrader Customer Service

                        Comment


                          #13
                          I think the problem is that the rectangles that draw the indicator are not globals. So, the script can't retrieve the information. I tried to do a manual rectangle in one chart, and then set this as global (checkin attach to all charts), and then I ran the script in the secondary chart where this rectangle is drawn and is the same situation, not working...

                          Comment


                            #14
                            so I think the indicator is hidden the rectangle anchors

                            Comment


                              #15
                              Hello federicoo,

                              Thanks for your replies.

                              The tag name is preceded by the "@" symbol which indicates a global draw object. In my test here I created a global rectangle on one chart and then on a different chart (of the same instrument) and ran a script that produced its own rectangle and then read all of the rectangles on the chart. The script was able to read both local and global rectangles.

                              Click image for larger version

Name:	fredericoo-3.PNG
Views:	484
Size:	53.8 KB
ID:	1099364

                              Can you provide further information on what is drawing the rectangle in question?
                              Paul H.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by judysamnt7, 03-13-2023, 09:11 AM
                              4 responses
                              59 views
                              0 likes
                              Last Post DynamicTest  
                              Started by ScottWalsh, Today, 06:52 PM
                              4 responses
                              36 views
                              0 likes
                              Last Post ScottWalsh  
                              Started by olisav57, Today, 07:39 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post olisav57  
                              Started by trilliantrader, Today, 03:01 PM
                              2 responses
                              21 views
                              0 likes
                              Last Post helpwanted  
                              Started by cre8able, Today, 07:24 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post cre8able  
                              Working...
                              X