Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Drawing tool that draws a Ray between Day Highs

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

    Drawing tool that draws a Ray between Day Highs

    Hi all! I’m looking for an indicator that will draw a Ray from High[1] to High[0]. I’d like to be able to limit the number of Rays to the most recent “n” candles.

    I’ve been able to write a strategy that can draw the rays but I can’t figure out how to limit it to the most recent “n” candles.

    Thanks in advance!

    #2
    Hello Learning134,

    Thanks for your post.

    Rays will draw from a StartAnchor to an EndAnchor defined by the Draw.Ray() startY and endY parameters that you pass to it.

    For example, say you call Draw.Ray(this, "tag1", 1, High[1], 0, High[0], Brushes.DodgerBlue);.

    This will draw a Ray on the chart from 1 bar ago to the current bar using a startY value of High[1] and an endY value of High[0].

    The line of a Ray will continue to go through that current High price since Ray drawing objects are designed to continue drawing the line forward on the chart.

    If you would like to draw a line from one bar to another bar and not continue forward, you could use Draw.Line(). This will draw a Line drawing object starting at one bar and ending on another bar.

    I have attached two demonstration scripts to this response. One example script draws a Ray on the chart. The second example script draws a Line on the chart from one bar to another bar.

    See the help guide documentation below for more information.

    Draw.Ray(): https://ninjatrader.com/support/help...8/draw_ray.htm
    Draw.Line(): https://ninjatrader.com/support/help.../draw_line.htm

    Please let me know if I may assist further.​
    Attached Files
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Hi Brandon,

      I was successful at writing a strategy that paints rays on a chart from all previous highs to the next high of a candle. It’s too many rays though. I want to be able to limit the number of rays painted to say 10 of the most current candles.

      Once painted does it stay painted with each new bar created? Or does every ray in the past get repainted with each new bar? If it’s painted once then I would need to find a way to undraw the rays for any candle that are beyond 10 candles.

      please advise.

      Comment


        #4
        Hello Learning134,

        Thanks for the clarification.

        A drawing object will be removed from its current location and redrawn at a new location if the Draw method is called using the same Tag name. If a drawing object has unique tag names, each time the Draw method is called, it will draw a new object on the chart.

        From the Tag parameter on the Draw.Ray() help guide page:
        "A user defined unique id used to reference the draw object.
        For example, if you pass in a value of "myTag", each time this tag is used, the same draw object is modified. If unique tags are used each time, a new draw object will be created each time."


        Draw.Ray(): https://ninjatrader.com/support/help...8/draw_ray.htm

        This means that if you call the Draw.Ray() method three times in your code and give them the Tag names "Ray1", "Ray2", and Ray3" as seen below, each time that Draw method is called, that specific Ray will be removed from its current location, and redrawn at the new location. The below code would draw a total of 3 Rays on the chart; not more than 3 Rays would be on the chart at a time.

        Draw.Ray(this, "Ray1", 10, Close[10], 0, Close[0], Brushes.LimeGreen);
        Draw.Ray(this, "Ray2", 10, Low[10], 0, Low[0], Brushes.HotPink);
        Draw.Ray(this, "Ray3", 10, High[10], 0, High[0], Brushes.Cyan);


        Please let me know if you have further questions.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Very helpful! Thank you!

          Next question. I would like to define some private “objects”(not sure that’s the correct terminology).

          LH = High[2] < High[1] && High[1] > High[2];
          GH = LH[2] < LH[1] && LH[1] > LH[2] ;

          What expression type do I define LH and GH to be so that they can be indexed and called back to?

          Thank you.

          Comment


            #6
            For the LH/GH to be indexed you would need to create them as a double data series.

            Reference: https://ninjatrader.com/support/help...ml?seriest.htm

            Comment


              #7
              Hello Learning134,

              Thanks for your note.

              Tasker-182 is correct. To access a variable using a BarsAgo index you would need to create custom Series<double> variables in your script.

              For example, if you have a custom Series<double> variable called 'myCustomSeries' then you could reference the current value by calling myCustomSeries[0] and the previous value by calling myCustomSeries[1].

              Please review this help guide page for information about how to create custom Series<double> variables in NinjaScript and assign values to them: https://ninjatrader.com/support/help...t8/seriest.htm

              You could also set up a custom Series variable in the 'Custom Series' section of the Additional Data screen of the Strategy Builder and click the 'View code' button to see the generated syntax.

              See this help guide page for more information: https://ninjatrader.com/support/help...onalDataScreen

              Let me know if I may further assist.​
              Brandon H.NinjaTrader Customer Service

              Comment


                #8
                Thank you Tasker-182 and Brandon H.! Very helpful information. Next questions:

                1) If I have a Ray that is created with anchors in the past, say High[15] and High[8], can I Get the current value/price level (y-axis value) that that Ray is at on the current bar[0]?

                2) To create a Ray between a private series, LH[2] to LH[1], how do I get the x-axis location (bar number) for this private series to set the anchor points for the Ray?

                Thank you for your continued assistance!

                Comment


                  #9
                  Yes, you can "predict" the rays future/current Y value at bar x by calculating the rate of rise and applying that to the Bar x location. (x being whatever bar number in the future). Please see this post for an example that demonstrates the concept: https://ninjatrader.com/support/foru...t8#post1071060

                  When you create a series, private or otherwise, it automatically indexes to the bars on the chart (exception would be if specifically aligned with a different time frame of an added series) . So if you have a means to find what you need through the bars of the chart then you can do that. For example if you need the bar number 17 bars ago from the current bar then the bar number would be equal to CurrentBar - 17. Try printing the value of CurrentBar and you should see the bar number

                  Comment


                    #10
                    Hello Learning134,

                    Thanks for your note.

                    Tasker-182 is correct. The YAxisProjection script shared by my colleague Paul on the post linked by Tasker-182 could be viewed to see how to calculate the slope of a ray, project the value of the ray on each new bar, and check the price value of the ray value on the current bar.

                    As Tasker-182 stated, a Series<T> variable will have the same index as the bars on the chart unless they are calculating off of a different timeframe of an added series. You could print out the CurrentBar value to see what the bar number of the current bar is on the chart.

                    See this help guide page for more information about working with Series<T> variables: https://ninjatrader.com/support/help...t8/seriest.htm

                    See this help guide page for more information about CurrentBar: https://ninjatrader.com/support/help...currentbar.htm

                    Let me know if I may assist further.
                    Brandon H.NinjaTrader Customer Service

                    Comment


                      #11
                      Hey BrandonH and Tasker-182,

                      Thanks for the great info above. Very helpful. Would either of you be open to me hiring you to tutor/teach me to build my project. I think I would progress exponentially faster. And if not could you recommend anyone.

                      Much gratitude. Learning134

                      Comment


                        #12
                        Hello Learning134,

                        Thanks for your note.

                        The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. You could find those affiliates in the link below.

                        Search trading apps & services to cusomize your NinjaTrader platform with trading indicators, signals and strategies.


                        Let me know if I may assist further.


                        The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
                        Brandon H.NinjaTrader Customer Service

                        Comment


                          #13
                          Thanks for the vendor page.

                          I have a basic question on the example YaxisProjectionofLine indicator. Why are the variables in the first method defined as private variables (x1, x2, y1Bar, etc.) but the variables in the second method are not defined at the top of the script and just used?

                          Is it because those that are defined at the top as private can be accessed throughout the entire script and those that are only defined within the method can only be accessed within that method? And then global variables would be accessible to other scripts?

                          Thanks
                          Last edited by Learning134; 01-07-2023, 03:49 PM.

                          Comment


                            #14
                            Hello Learning134,

                            Thanks for your note.

                            The 'doItOnce' bool variable is initially set to true when the variable is created.

                            private bool doItOnce = true;

                            The script then checks if the bool is true, assigns a value to the other variables such as y1 and y2, draws the ray, then the script sets the 'doItOnce' bool to false.

                            if (doItOnce) // on the first live bar, draw a ray starting from the low 5 bars ago to the high of the current bar
                            {
                            x2Bar = 0;
                            x1Bar = 5;
                            y1 = Low[5];
                            y2 = High[0];
                            x1bbar = CurrentBar - 5;
                            Draw.Ray (this, "test"+CurrentBar, x1Bar, y1, x2Bar, y2, Brushes.CornflowerBlue);

                            doItOnce = false;
                            }


                            Next, the script checks if the bool is false, performs mathematical calculations using the variables that were assigned values in the previous condition, and draws dots on the chart based on the calculated values.

                            if (!doItOnce)
                            {
                            // First calculate slope of line
                            double runrate = (y2 - y1) / 5;

                            // Now project the slope to new bar
                            double projecty = runrate * (CurrentBar - x1bbar);

                            // to demonstrate that we know where the ray line is
                            Draw.Dot (this, "t1"+CurrentBar, true, 0, projecty + y1, Brushes.Gold);

                            // so to test for price crossing the ray, you would use the projecty + y1 as the Y value to test
                            // for example if (Close[0] > (projecty+y1)
                            }


                            Let me know if I may assist further.
                            Brandon H.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by poplagelu, Today, 05:00 AM
                            0 responses
                            3 views
                            0 likes
                            Last Post poplagelu  
                            Started by fx.practic, 10-15-2013, 12:53 AM
                            5 responses
                            5,407 views
                            0 likes
                            Last Post Bidder
                            by Bidder
                             
                            Started by Shai Samuel, 07-02-2022, 02:46 PM
                            4 responses
                            98 views
                            0 likes
                            Last Post Bidder
                            by Bidder
                             
                            Started by DJ888, Yesterday, 10:57 PM
                            0 responses
                            8 views
                            0 likes
                            Last Post DJ888
                            by DJ888
                             
                            Started by MacDad, 02-25-2024, 11:48 PM
                            7 responses
                            160 views
                            0 likes
                            Last Post loganjarosz123  
                            Working...
                            X