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

Drawing rays from a dataseries

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

    #31
    Hello Kay,

    Using lists is not specific to NinjaScript but is instead general c#. (Meaning there is not information about lists in the NinjaTrader help guide.)

    Is using a list required for your code? (Can you code your script without using a list?)

    Below I am including a link to a 3rd party site that teaches using lists.
    Create a new List, add elements to it, and loop over its elements with for and foreach.


    For example:
    In #region Variables:
    private List<int> barNumbers = new List<int>();

    In OnBarUpdate():
    barNumbers.Add(CurrentBar);

    for (var i = 0; i < barNumbers.Count; i++)
    {
    Print(barNumbers[i]);
    }

    This would print out all of the bar numbers on ever bar. (a list that would get longer on each bar)
    Chelsea B.NinjaTrader Customer Service

    Comment


      #32
      Hi Chelsea,

      A dataseries wouldn't have been ideal because of the zeroes that occur between relevant points. A list seemed like a good idea as it eliminated the zeroes but presented a whole new set of problems. The second last option would be a multidimensional array but not sure what new issues that would create.

      Ideally what i'm trying to achieve, after identifying demandpoints, is to draw rays from these points as long as the point to the right of it is greater than it. There are occasions where there will be multiple rays emanating from a point provided the condition is valid.

      When I initially thought I had the logic correct, I thought I could access the individual demandpoints from the list at will. At that time, I believed the only problem I had, was working out the bars ago to draw the rays.

      Happy to hear suggestions you may have.

      Regards
      Kay Wai

      Comment


        #33
        Hello Kay,

        I don't have any information with which to provide you with suggestions.

        If you use a bars ago value for the start point and provide a price value, and a bars ago value for the end point and a price value, and supply these to DrawRay it will draw the ray between those two points.

        My suggestion would be to use the correct bars ago value and correct price for the start point and end point.

        DrawRay("ray"+CurrentBar, barsAgoStartValue, priceStartValue, barsAgoEndValue, priceEndValue, Color color)

        DrawRay(string tag, int anchor1BarsAgo, double anchor1Y, int anchor2BarsAgo, double anchor2Y, Color color)

        http://ninjatrader.com/support/helpG...t7/drawray.htm

        As far as your list is concerned, I would make sure the list is being populated and that you can print the values.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #34
          Originally posted by kaywai View Post
          Hi Chelsea and Koganam,

          Thank you so much for your help these past few days. I think I have most of the logic out for me to fiddle around with the code except for the bar numbers or bars ago on which I want to draw the ray.

          The list counts don't tally with the bar numbers and that is where I am stuck at the moment.

          Could either of you or anyone point me to the right direction?

          Regards

          Kay Wai
          Not to be snarky, but this kind of unclear coding is the usual result of skipping basics, and starting to write code without first writing down a clear technical specification of what you want to code, so that you can design the appropriate logic.

          I note that you seem to be wring code for T*Lines. Even a perfunctory reading of the description of such would show that you need exactly 2 points to define a T*Line. From the Jason Perl book, D*Mark Indicators, we get this ditty (emphasis mine).
          Unlike the trendlines in traditional technical analysis, which require
          a minimum of three points to construct, a TD Line needs only two
          reference points
          . Furthermore, in recognition of the fact that markets
          are dynamic and that recent price action is arguably more significant
          than price action further in the past, TD Lines are drawn from right to
          left, rather than left to right, using the two most recent TD Points. To
          determine support, connect the two most recent TD Demand Points
          of the same magnitude (from right to left) to draw an upward-sloping
          TD Demand Line. To determine resistance, connect the two most
          recent TD Supply Points of the same magnitude (from right to left) to
          draw a downward-sloping TD Supply Line
          Given that we need only 2 points, why all this talk about iterating through lists and whatnots? In actuality, because we are analyzing/editing a data stream and not a static stochastic space, we only really need the last point stored, as when we get the current point, we can finish our analysis first, then store the current point for use in the next determination.

          So, let us go to basics. First, write up a specification of how you want to code. Then, I can help iron out your errors if any.
          Last edited by koganam; 01-07-2016, 03:42 PM.

          Comment


            #35
            Hi Koganam,

            What the book tells you is one thing and what happens in reality is another. If you have Bloomberg or CQG handy, you will know what I'm talking about.

            I will try to lay out the logic first then I will revert. Thanks for offering to help.

            Regards

            Kay Wai

            Comment


              #36
              Originally posted by kaywai View Post
              Hi Koganam,

              What the book tells you is one thing and what happens in reality is another. If you have Bloomberg or CQG handy, you will know what I'm talking about.

              I will try to lay out the logic first then I will revert. Thanks for offering to help.

              Regards

              Kay Wai
              Actually, no it is not. You are seeing the mass/mess of extended lines that are earlier rays drawn. What you see on the Bloomberg terminal exactly matches the description in the book. The pictures in Perl's book come from a Bloomberg terminal.

              I coded this once a long time ago, but lost the file along with everything else in a fire a few years ago.

              I found an old picture, but, unfortunately not the code. It looked like this. Compare it to your Bloomberg terminal over the same dates and instrument, and you will see what I mean.
              Attached Files
              Last edited by koganam; 01-08-2016, 04:18 PM. Reason: Added picture.

              Comment


                #37
                Imho, it is messy at the beginning but once you know what you're looking for, the mess just disappears!

                Comment


                  #38
                  Originally posted by kaywai View Post
                  Imho, it is messy at the beginning but once you know what you're looking for, the mess just disappears!
                  That sentiment is true enough, but I was simply pointing out that your statement: "What the book tells you is one thing and what happens in reality is another. If you have Bloomberg or CQG handy, you will know what I'm talking about." is not quite correct, and why what you are seeing may have misled you into making that statement.

                  Comment


                    #39
                    Hi All,

                    The good news is I managed to draw a line! The bad news is it only draws one miserable line at the beginning when the conditions are true. Any idea how I can get these lines to populate?

                    I tried adding "CurrentBar" to the tag but that didn't work. I've attached the code and a chart for references. Any help/suggestions is much appreciated.

                    Regards

                    Kay Wai
                    Attached Files

                    Comment


                      #40
                      Originally posted by kaywai View Post
                      Hi All,

                      The good news is I managed to draw a line! The bad news is it only draws one miserable line at the beginning when the conditions are true. Any idea how I can get these lines to populate?

                      I tried adding "CurrentBar" to the tag but that didn't work. I've attached the code and a chart for references. Any help/suggestions is much appreciated.

                      Regards

                      Kay Wai
                      Without commenting on the rest of your code, which, given your drawing, may well be working correctly, I see this:
                      Code:
                      				else if ((DemandPointa > 0) && (DemandPointb > 0))
                      				{
                      					DrawLine( "mydemandline", CurrentBar - startbarsago+1, DemandPointa, CurrentBar - endbarsago+1, DemandPointb, Color.Black);	
                      				}
                      Your tag is "mydemandline", which identifies a single object. Ergo, only one object will be drawn. In other words, your statement that: ' I tried adding "CurrentBar" to the tag ...', seems to be inaccurate. Correct that for a start.

                      That it would appear that the line is being drawn at the same exact location each time, would mean that your anchor references are also probably defective. Look again at how you are defining where the drawing should be placed. But one thing at a time.
                      Last edited by koganam; 01-17-2016, 01:02 PM.

                      Comment


                        #41
                        Hi Koganam,

                        I've attached the chart and code with your suggestions. Obviously something is not working. Would you please mind taking a look?

                        Thanks in advance
                        Kay Wai
                        Attached Files

                        Comment


                          #42
                          Hello Kay,

                          As Kognam mentioned in post #40, the DrawLine call is using a tag that is not unique. This means only one line can be drawn, as each time it is called with that same tag name the line will be removed and re-drawn in the new location instead of a new line being drawn.

                          Your DrawSquare call uses a tag name that is unique on each bar, your DrawLine call does not.

                          DrawSquare("mydemandpoint" + CurrentBar, true, 1, TDTrueLow().TL[1], Color.Black);
                          "mydemandpoint" + CurrentBar is unique on each bar as it adds the number of the bar to the string which changes on each bar. This will create a new square each time it is called. I am seeing that there are multiple squares on your chart.

                          DrawLine( "mydemandline", CurrentBar - startbarsago+1, DemandPointa, CurrentBar - endbarsago+1, DemandPointb, Color.Black);
                          "mydemandline" is not unique and will not create multiple lines but will move the existing line each time it is called.


                          Further, if this line is at the beginning of the chart, this means that each time you call this, the start and end point bars ago values may be the same.

                          I recommend that you print the bars ago values each time the DrawLine is called so that you know how many bars ago the start point and end points are being drawn.

                          Print(string.Format("{0} | start bars ago: {1} | end bars ago: {2}", Time[0], CurrentBar - startbarsago+1, CurrentBar - endbarsago+1));

                          Please post the output from the output window created by this print.
                          Last edited by NinjaTrader_ChelseaB; 01-19-2016, 08:07 AM.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #43
                            Hi Chelsea & Koganam,

                            I got the lines to draw! What was missing, was resetting DemandPointa and DemandPointb back to zero after drawing the line. The only issue now is there are some line that are not drawn. (please see attached chart). I've just circled 4 occasions as an example.

                            Any ideas what I'm doing wrong?

                            Regards

                            Kay Wai
                            Attached Files

                            Comment


                              #44
                              Hello Kay,

                              What is the output you are getting from the prints for that bar that should be drawing the lines on those bars?

                              Can you include the output in your next post?
                              Chelsea B.NinjaTrader Customer Service

                              Comment


                                #45
                                Hi Chelsea,

                                Attached is the output file.

                                And Koganam,

                                I managed to find an old Bloomberg screenshot just for you!

                                Best Regards

                                Kay Wai
                                Attached Files

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by burtoninlondon, Today, 12:38 AM
                                0 responses
                                10 views
                                0 likes
                                Last Post burtoninlondon  
                                Started by AaronKoRn, Yesterday, 09:49 PM
                                0 responses
                                14 views
                                0 likes
                                Last Post AaronKoRn  
                                Started by carnitron, Yesterday, 08:42 PM
                                0 responses
                                11 views
                                0 likes
                                Last Post carnitron  
                                Started by strategist007, Yesterday, 07:51 PM
                                0 responses
                                13 views
                                0 likes
                                Last Post strategist007  
                                Started by StockTrader88, 03-06-2021, 08:58 AM
                                44 responses
                                3,983 views
                                3 likes
                                Last Post jhudas88  
                                Working...
                                X