Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Price crossing a line

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

    Price crossing a line

    Hello

    Is there a way to know if the current price crossed a line which was drawn by gui or from Draw.Line?

    Thanks

    #2
    Hello kiss987,

    Thanks for your post.

    Yes, you would need to loop through a collection of draw objects and determine which line(s) you wanted to check the price against, obtain the anchor prices of the line and compare price to the anchor price.

    Please see this section of the helpguide for sorting through a draw objects collection: https://ninjatrader.com/support/help...rawobjects.htm

    Comment


      #3
      Assuming the object named "draw" of type DrawingTools.Line is my line, how do I know its value at barsAgo = 0 (current time)?

      Thanks

      Comment


        #4
        Hello kiss987,

        Thanks for your reply.

        If the line is a horizontal line type then you would only need the start anchor price as the price level does not change for the length of the line

        If the line is a line (which can be of any length and any direction) then you would need to obtain the Start anchor price and bar and the end anchor price and bar, then extend mathematically a projection of the line to the current bar to then calculate the lines price at that bar.

        Comment


          #5
          Hello

          How can I extend mathematically a projection of the line (which can be of any length and any direction) to the current bar to then calculate the lines price at that bar?

          Thank you

          Comment


            #6
            Hello kiss987,

            Thanks for your reply.

            You would determine the slope of the line based on the start and end anchor bars and the start and end anchor prices and then use the slope to project what the Y value would be at X location.

            I've attached an example script that draws a ray (for visual purposes) then calculates its slope and projects where the Y value would be for each subsequent bar by plotting a dot on the ray.

            YAxisProjectionOfLine.zip
            Last edited by NinjaTrader_PaulH; 12-10-2020, 10:44 AM. Reason: Reworked the example indicator to better reference X and Y values, was confusing the way I originally wrote it.

            Comment


              #7

              sorry this was not going here
              Last edited by RubenCazorla; 04-13-2021, 06:54 AM.

              Comment


                #8
                Hello RubenCazorla,

                Thanks for your post.

                You can use my example indicator in Post#6 to understand how you can obtain the bar-to-bar values of the drawn line.

                Comment


                  #9
                  Hi Paul,

                  Thank you very much, the projection is SO brilliant.

                  When trying to understand this sample and adapting it to a Swing ray, I've come to find that it would have been even more explicit and simple to understand by modifying line 74.
                  Would you agree that the int denominator can be replaced by the substraction of the previously declared variables ?
                  Attached Files
                  Last edited by Amedeus; 07-14-2021, 04:36 AM.

                  Comment


                    #10
                    Hello Amedeus,

                    Thanks for your post.

                    I agree.

                    Comment


                      #11
                      Originally posted by NinjaTrader_PaulH View Post
                      Hello kiss987,

                      Thanks for your reply.

                      You would determine the slope of the line based on the start and end anchor bars and the start and end anchor prices and then use the slope to project what the Y value would be at X location.

                      I've attached an example script that draws a ray (for visual purposes) then calculates its slope and projects where the Y value would be for each subsequent bar by plotting a dot on the ray.

                      [ATTACH]n1131703[/ATTACH]
                      Hello Paul,

                      What changes would be necessary in your example to determine the exact point where a user-drawn (line or ray) is crossed over?

                      Comment


                        #12
                        Hello bobperez,

                        The sample that is posted in this thread is not intended to be used with user drawn lines, that script draws the ray itself using specific bars ago which relate to the series the script is applied to. It then calculates a projection using the bar and price data as that script processes.

                        For a user drawn objects those won't have anchors that use bars ago, those are tied to chart slots. Because of that you could only use the anchors time to get a bar near that time depending on the series your script is using.

                        For an object that has two anchors which reside at the start and end points that you wanted you could get the anchor times and use those times with the GetBar method to get the closest bar to that time for the series being used. You could then do the math to calculate the slope between those points. That calculation could then be used to calculate prices for any bar between those points based on a bars ago similar to the attached sample. For a Ray that would be different because a ray does not need to have its anchor on the end bar, a ray may only be 1 bars ago for the anchors difference but it will still project to the chart panels edge beyond where the bars are. With that use case you would have to do similar to the sample and use the bars ago and prices to calculate a slope but then also do a future projection to find what the price may be in the rays extension beyond its anchors.

                        Comment


                          #13
                          Hi Jesse,

                          Thank you for your reply. I understood the concept you explained, but from there to an actual implementation, I'm having a hard time. Do you have a simple example of your explanation from where I could start?

                          Bob

                          Comment


                            #14
                            Hello bobperez,

                            I am not aware of a sample like that, it would be something you would likely need to create however this would be a fairly complex task.

                            Because manual drawing objects use slots that would be less accurate that the linked sample. Depending on where the user places the object that could end up between two bars or closer to one than the other rather than directly on a bar. Because of that the bar found by its time may only be near the anchors actual placement which would cause differences in your calculations. When comparing a value against the slope that you calculate it may not directly match up with what you see in the chart. The reason the calculation in the attached sample works is because it uses fixed bars ago for the series the script is using so it directly matches where the object is drawn.

                            There are other aspects that would make doing this difficult, for example user drawn objects can only be seen by a script while running in realtime so there would not be a easy way to test this programmatically like the sample in this thread. If you draw new objects the results will change each time, once enough time elapses and bars progress you won't have the same test because you will need to draw a new object on the new bars.

                            Objects also can be manually drawn into the future but there are no bars for those times, there are just chart slots. Trying to look up a future bar by a future time would not work because it does not exist.

                            Comment


                              #15
                              Originally posted by NinjaTrader_PaulH View Post
                              Hello Amedeus,

                              Thanks for your post.

                              I agree.
                              Hi PaulH,

                              I have spent several hours trying to determine the crossing prices of any user-drawn line, with start/end points occurring not only at the current bar but also at previous bars. My objective is to use this indicator information to make it available to a strategy that will utilize the crossing prices to make entry decisions. Can you please suggest how to achieve this, if you have an example other than YAxisLineCross, I would appreciate it greatly.

                              Thank you,

                              Bob

                              Comment

                              Latest Posts

                              Collapse

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