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

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
    Paul H.NinjaTrader Customer Service

    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.
        Paul H.NinjaTrader Customer Service

        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.
            Paul H.NinjaTrader Customer Service

            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.

                Paul H.NinjaTrader Customer Service

                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.
                    Paul H.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by bsbisme, Yesterday, 02:08 PM
                    1 response
                    15 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by prdecast, Today, 06:07 AM
                    0 responses
                    3 views
                    0 likes
                    Last Post prdecast  
                    Started by i019945nj, 12-14-2023, 06:41 AM
                    3 responses
                    60 views
                    0 likes
                    Last Post i019945nj  
                    Started by TraderBCL, Today, 04:38 AM
                    2 responses
                    18 views
                    0 likes
                    Last Post TraderBCL  
                    Started by martin70, 03-24-2023, 04:58 AM
                    14 responses
                    106 views
                    0 likes
                    Last Post martin70  
                    Working...
                    X