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

Calculating Cross Section of Two Trend Lines

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

    Calculating Cross Section of Two Trend Lines

    Dear Support,

    Is there a function available in NT8 to calculate X and Y values for cross section of two converging trend lines? For example, I want two converging trend lines to stop drawing at the point of crossing each other.

    I know the math to calculate the X and Y values for cross point of two equations. However, considering that the in Ninja the X value (bar number) is an Integer and the Y value (DataSeries) is a Double, the calculation becomes a bit tricky. As such, drawing an object or establishing an anchor point at the cross section, at best, seems requiring special treatment.

    Any information would be appreciated.

    Many thanks.
    Last edited by aligator; 06-16-2017, 06:16 PM.

    #2
    Hello aligator,

    Are you referring the trend lines included with NinjaTrader as a drawing tool?

    As in, Draw.TrendChannel() and you would be wanting to know where two of these objects are crossing?


    There would not be a function for this and would require custom calculations.


    Are you referring to plots that are made by an indicator or set of indicators?
    Using plots it would be possible to tell if the previous bar is not equal and then on the current bar is equal or crossing.


    If you are creating your own rendering of a line or path in OnRender you can get a bar number or price for any x and y coordinate and use this to check the previous bar not being equal and the current bar equal or crossing.
    GetValueByY() - http://ninjatrader.com/support/helpG...etvaluebyy.htm
    GetSlotIndexByX() - http://ninjatrader.com/support/helpG...otindexbyx.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I have had a similar problem with calculating intersections of two plots for determining the fill area.

      When I use Draw.Region() with crossing moving averages, it becomes ugly, because DrawRegion() is not designed to adjust to the crossing points.

      There is a second shortcoming of Draw.Region() as it does not correctly align to the indicator plots at the right end of the chart.

      The only solution here is to override OnRender() and do all necessary pixel calculations in OnRender().
      Attached Files
      Last edited by Harry; 06-19-2017, 02:06 AM.

      Comment


        #4
        Originally posted by NinjaTrader_ChelseaB View Post
        Hello aligator,

        Are you referring the trend lines included with NinjaTrader as a drawing tool?

        As in, Draw.TrendChannel() and you would be wanting to know where two of these objects are crossing?


        There would not be a function for this and would require custom calculations.


        Are you referring to plots that are made by an indicator or set of indicators?
        Using plots it would be possible to tell if the previous bar is not equal and then on the current bar is equal or crossing.


        If you are creating your own rendering of a line or path in OnRender you can get a bar number or price for any x and y coordinate and use this to check the previous bar not being equal and the current bar equal or crossing.
        GetValueByY() - http://ninjatrader.com/support/helpG...etvaluebyy.htm
        GetSlotIndexByX() - http://ninjatrader.com/support/helpG...otindexbyx.htm

        Hi Chelsea,

        The issue relates to filling between any two lines and NT8 is not currently handling it correctly. As Harry noted above, the filling does not start or terminate at the point of two lines crossing.

        Calculation of crossing coordinates for Line a---b and line c---d is simple algebra and is at the point where the formula for these two lines become equal

        Y = (Slope)ab * X + yb and Y = (Slope)cd * X + yd

        Where for:

        Line a--b a = bar[1] and b = bar[0]
        Line c--d c = bar[1] and d = bar[0]

        At crossing point these two equations become equal, thus

        (Slope)ab * X + yb = (Slope)cd * X + yd and

        X = (yd - yb) / ((Slope)ab - (Slope)cd)

        Now we can substitute the value for X in one of the equations and calculate Y for the crossing point.

        The problem here is that while Y value is a data series (double) the X value is always an integer, regardless of bar type, but is also calculated as a double. Therefore the use of a time-based scale instead of bar numbers as suggested by PatrickH in a different thread will never produce the correct X location either, even at the lowest time unit (seconds).

        The only way to produce a near correct X location will be to calculated the X location at horizontal pixels count away from the the current bar. This is not the exact mathematical location either but will produce the correct fill within the limits of the allowed pixel resolution.

        This explanation is meant to help communicate my question. I believe Harry indicated in the past that he had come up with a method that he was willing to share with NinjTrader, but apparently there has not been any follow up since the issue still exists.

        Perhaps if Harry can share his method (script) here, absent any actions from NinjaTrader, we can resolve this nagging issue for good.

        Cheers!
        Last edited by aligator; 06-18-2017, 07:37 PM.

        Comment


          #5
          Hello aligator,

          So to confirm, you are referring to using Draw.Line() and you are not referring to custom rendering in C#, is this correct?
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_ChelseaB View Post
            Hello aligator,

            So to confirm, you are referring to using Draw.Line() and you are not referring to custom rendering in C#, is this correct?
            Hi Chelsea,

            Not really. Perhaps Draw.Region() is a good example. Please refer to first screenshot from Harry in post #3 regarding fill between 2 lines.

            The rendering of the fill is not at the correct crossing point. I think NT8 does not use correct coordinates at the crossings for use in rendering.

            Thanks.
            Last edited by aligator; 06-18-2017, 07:57 PM.

            Comment


              #7
              Originally posted by aligator View Post
              Hi Chelsea,

              Not really. Perhaps Draw.Region() is a good example. Please refer to first screenshot from Harry in post #3 regarding fill between 2 lines.

              The rendering of the fill is not at the correct crossing point. I think NT8 does not use correct coordinates at the crossings for use in rendering.

              Thanks.

              Hi Aligator,

              Draw.Region() has not been designed to be used with crossing lines. This is like complaining that a car cannot fly. NinjaTrader has next to illimited possibilities in designing whatever you like, but you need to code it.

              What you try to achieve, can only be done in OnRender(), because Draw.Region() is - by design - attached to the x-coordinates of the bars.

              I am happy to share the code of the indicator with you, if it helps. Just send me a private message with your e-mail and I will send you the indicator,

              Comment


                #8
                Originally posted by Harry View Post
                Hi Aligator,

                Draw.Region() has not been designed to be used with crossing lines. This is like complaining that a car cannot fly. NinjaTrader has next to illimited possibilities in designing whatever you like, but you need to code it.

                What you try to achieve, can only be done in OnRender(), because Draw.Region() is - by design - attached to the x-coordinates of the bars.

                I am happy to share the code of the indicator with you, if it helps. Just send me a private message with your e-mail and I will send you the indicator,
                Thank you Harry,

                Not a question of complaining, just a fact that Draw.Region, however designed, does not fill the region correctly.

                Thanks.
                Last edited by aligator; 06-19-2017, 10:12 AM.

                Comment


                  #9
                  Originally posted by aligator View Post
                  Thank you Harry,

                  Not a question of complaining, just a fact that Draw.Region, however designed, does not fill the region correctly.

                  Yes, thank you. Please send PM to @aligator on Futures.io.

                  Thanks.

                  OK. Will send you the code.


                  Harry

                  Comment


                    #10
                    Hello aligator,

                    It is expected that the DrawRegion may not fill the region all the way to crossing plots or past them as the fill coloring is from the center of a bar to the center of another bar.

                    Would you like to submit a feature request for the NinjaTrader Development to consider recoding the DrawRegion to fill past (or stop short of) the middle of a bar to the exact point of where two plots are crossing in a future version of NinjaTrader?
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_ChelseaB View Post
                      Hello aligator,

                      It is expected that the DrawRegion may not fill the region all the way to crossing plots or past them as the fill coloring is from the center of a bar to the center of another bar.

                      Would you like to submit a feature request for the NinjaTrader Development to consider recoding the DrawRegion to fill past (or stop short of) the middle of a bar to the exact point of where two plots are crossing in a future version of NinjaTrader?
                      Thanks Chelsea,

                      I guess the question has been around for sometimes and was brought up a few times. It is certainly proper if fill for draw region would terminate or start at the the cross instead of middle of the bar.

                      Cheers!

                      Comment


                        #12
                        Hello aligator,

                        For future reference, your request for Draw.Region to fill the exact point where two plots cross is being tracked with ID #SFT-2392.

                        Please note it is up to the NinjaTrader Development to decide if and when a feature request will be implemented.

                        Thank you for your feedback. Please let me know of any other suggestions you have for the NinjaTrader platform.
                        Chelsea B.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Mestor, 03-10-2023, 01:50 AM
                        16 responses
                        388 views
                        0 likes
                        Last Post z.franck  
                        Started by rtwave, 04-12-2024, 09:30 AM
                        4 responses
                        31 views
                        0 likes
                        Last Post rtwave
                        by rtwave
                         
                        Started by yertle, Yesterday, 08:38 AM
                        7 responses
                        29 views
                        0 likes
                        Last Post yertle
                        by yertle
                         
                        Started by bmartz, 03-12-2024, 06:12 AM
                        2 responses
                        22 views
                        0 likes
                        Last Post bmartz
                        by bmartz
                         
                        Started by funk10101, Today, 12:02 AM
                        0 responses
                        7 views
                        0 likes
                        Last Post funk10101  
                        Working...
                        X