Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Get coordinates from Rectangle on chart

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

    Get coordinates from Rectangle on chart

    Hello i want to create a volume profile based on ninjatrader sample VP. But i want to get y x or price and time coordinates from a rectangle that i draw with a specified name lets say "VPR".

    I already know that onRender can get x y from as example
    Code:
     xCoordinate = chartControl.GetXByBarIndex(ChartBars, 100);
    and i also try to give a parameter like a string which would be the name so search chart for the object with the specified name and return me the value but no luck.

    In MQL4 we had something like ObjectGet();

    What is the equivalent in Ninjascript?

    Thank a lot !

    #2
    Hello stoxos,

    Thank you for your response.

    Is the rectangle manually drawn or drawn in code?

    You can loop through the draw objects with the example at the following link: http://ninjatrader.com/support/helpG...rawobjects.htm

    I look forward to your response.

    Comment


      #3
      Hmm thank you for your response, But DrawObjects works on OnBarUpdate() i have my code on OnMarketData because i use tickreplay. So if i use it on OnBarUpdate() there are two problems:
      1) I need open markets or market replay
      2)The indicator will update each new bar which is a problem since i want the user to be able to use the lines or rectangle object anytime he wants and almost instantly get his result on chart.

      For the time i left rectangle and i try to create a volume profile with range between two vertical lines. I want to take the time from each of those lines for the profile calculation start and end.

      So how i can find the lines from OnMarketData and take there values of datetime?

      P.S. even on the example i so that i can lets say change each color or width of the object but how i get the values?
      Code:
        // An alternative approach to find the draw object by a tag
        if (DrawObjects["someTag"] as DrawingTools.Line != null)
        {
          // Do something drawing tool line
        }
      Thank you!

      Comment


        #4
        Hello stoxos,

        Thank you for your response.

        You can loop through the objects in OnMarketData as well just ensure you check that ChartControl is not null: http://ninjatrader.com/support/helpG...artcontrol.htm

        Depending on the object you pull from the loop you will want to refer to it's properties directly through IDrawingTool: http://ninjatrader.com/support/helpG...rawingtool.htm

        Please let me know if you have any questions.

        Comment


          #5
          Ok i try to understand this is an example i create a text and i get its value from "Anchor.Time" and i also i can print the value!

          Code:
          			Text myText = Draw.Text(this, "tag", "test", 0, High[0]);     
          			  
          			  if(myText != null)
          			  {           
          			    Print(myText.Anchor.Time); 
          			  }
          But on VerticalLine there is no "Anchor" there is "Anchors". And then when i try to insert the following code
          Code:
          VerticalLine myLine = Draw.VerticalLine(this, "tag1", 10, Brushes.Black);
          my Volume profile doesnt draw at all. So it works with text object but not with vertical line. I dont know why. I tried also onRender and onBarUpdate still the same happens my code is the same as ninjatrader volume profile sample.

          Can you provide please an example of code where you get from a vertical line the value of time ? Cause i have messed up!


          P.s. i dont need to loop since i have the specified tag of the object

          Thank you!

          Comment


            #6
            Search for MouxeXYToBarTimePriceExample_NT8.zip

            It will do what you are asking

            Comment


              #7
              Originally posted by ballboy11 View Post
              Search for MouxeXYToBarTimePriceExample_NT8.zip

              It will do what you are asking
              Thank you, i done a search on google and in the ninjatrader forum but couldnt find that. Can you please upload it here if you have it?

              Comment


                #8


                i put it here because I don't know how to upload a file. I did get this from Ninjatrader formus somewhere

                Comment


                  #9
                  Originally posted by ballboy11 View Post
                  https://drive.google.com/file/d/0B6E...ew?usp=sharing

                  i put it here because I don't know how to upload a file. I did get this from Ninjatrader formus somewhere
                  Thank you for your help but it so not what i am looking for, i need to get the value from the object not the mouse.

                  Thank you

                  Comment


                    #10
                    //Create a class of rectangle parameters

                    public class PatternTextLocation
                    {
                    public DateTime STARTTIME;
                    public DateTime ENDTIME;
                    public double STARTYCOORD;
                    public double ENDYCOORD;




                    public PatternTextLocation(DateTime tStartTime,tEndTime)
                    {
                    STARTTIME = tStartTime;
                    ENDTIME = tEndTime;
                    etc, etc.

                    }

                    }


                    //create a list

                    private List<PatternTextLocation> PatternTextTimeLocation; // an array of timestamps when the rectangles were printed historically or live




                    in OnBarUpdate()

                    {


                    if(this.PatternTextTimeLocation == null)
                    this.PatternTextTimeLocation = new List<PatternTextLocation>();

                    // this is the line you need when adding you object class in you logic

                    this.PatternTextTimeLocation.Add(new PatternTextLocation(parameter in your class));

                    Comment


                      #11
                      Originally posted by stoxos View Post
                      Can you provide please an example of code where you get from a vertical line the value of time ? Cause i have messed up!
                      Hello stoxos,

                      Thank you for your patience.

                      Below is an example of pulling the time. I use a loop but the same concept applies to the object.
                      Code:
                      			foreach (DrawingTool draw in DrawObjects)
                      			{
                      				if (draw is VerticalLine && draw.Name == "Vertical Line")
                      				{
                      					VerticalLine vLine = draw as VerticalLine;
                      					Print(vLine.StartAnchor.Time);
                      				}
                      			}
                      Please let me know if you have any questions.

                      Comment


                        #12
                        Originally posted by ballboy11 View Post
                        //Create a class of rectangle parameters

                        public class PatternTextLocation
                        {
                        public DateTime STARTTIME;
                        public DateTime ENDTIME;
                        public double STARTYCOORD;
                        public double ENDYCOORD;




                        public PatternTextLocation(DateTime tStartTime,tEndTime)
                        {
                        STARTTIME = tStartTime;
                        ENDTIME = tEndTime;
                        etc, etc.

                        }

                        }


                        //create a list

                        private List<PatternTextLocation> PatternTextTimeLocation; // an array of timestamps when the rectangles were printed historically or live




                        in OnBarUpdate()

                        {


                        if(this.PatternTextTimeLocation == null)
                        this.PatternTextTimeLocation = new List<PatternTextLocation>();

                        // this is the line you need when adding you object class in you logic

                        this.PatternTextTimeLocation.Add(new PatternTextLocation(parameter in your class));
                        I used StartAnchor.Time. It gets the job done. Thank you a lot my friend for your answer and time!

                        Comment


                          #13
                          Originally posted by NinjaTrader_PatrickH View Post
                          Hello stoxos,

                          Thank you for your patience.

                          Below is an example of pulling the time. I use a loop but the same concept applies to the object.
                          Code:
                          			foreach (DrawingTool draw in DrawObjects)
                          			{
                          				if (draw is VerticalLine && draw.Name == "Vertical Line")
                          				{
                          					VerticalLine vLine = draw as VerticalLine;
                          					Print(vLine.StartAnchor.Time);
                          				}
                          			}
                          Please let me know if you have any questions.
                          BINGO!! Thats it "StartAnchor". It just is not listed when i press the dot after the line thats why i couldnt find it.

                          Thank you for the great support again!

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          637 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          366 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          107 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          569 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          571 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X