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

    #46
    Originally posted by kaywai View Post
    Hi Chelsea,

    Attached is the output file.

    And Koganam,

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

    Best Regards

    Kay Wai
    Yes, I can see joining of lines to points which are not adjacent. I guess Jason Perl's description must no longer be current. D*Mark does keep updating his methods. In other words, you are right: that drawing does not match the description in the Perl book.

    But I cannot see the method in that madness, as some intermediate points are being skipped while drawing the lines which are supposed to be at the same level. Are the green lines supposed to be level-5 lines?

    Comment


      #47
      Hello Kay,

      Lets take a particular instance and analyze this.

      Your screenshot has a wide range and the scaling means I am not able to see the dates of the bars on the chart so I am basically counting these.

      Are you using Kinetick with the USDMYR.FXCM symbol mapping?
      What time zone are you in?
      What session template is set with this chart? (Is this the forex session template?)


      From your circle it looks like you are expecting a line to be drawn from October 26th to Oct 19th.

      Can you clarify the dates of the bars where you are expecting a line to be drawn?

      This line would be triggered after those bars have passed using a bars ago value.

      The first date that shows this would have drawn is 10/27:
      10/27/2015 12:00:00 PM | start bars ago: 11 | end bars ago: 7

      This would have drawn from the 16th back to the 12th and this is appearing on the chart.

      The next line drawn is drawn on November 19th.
      11/19/2015 1:00:00 PM | start bars ago: 10 | end bars ago: 5

      This would have drawn from the 12th back to the 5th and we can also see this in the screenshot.


      On what bar date are you expecting the line to be drawn?
      When this triggers on what bar should the start point be and the end point be?


      Lets add a print outside of the condition that draws the line that prints these values so we can understand why the line is not being drawn.

      Please add the following print to the first line of OnBarUpdate().
      Code:
      Print(string.Format("{0} | TL[1]: {1} < TL[0]: {2} && TL[1]: {3} < TL[2]: {4} && DemandPointa: {5} > 0 && DemandPointb: {6} > 0", Time[0], TDTrueLow().TL[1], TDTrueLow().TL[0], TDTrueLow().TL[1], TDTrueLow().TL[2], DemandPointa, DemandPointb));
      Remove the other prints as we already have the output for those.

      Then clear the output window and re-run this script.

      In your next post, let me know the trigger bar, start bars ago, end bars ago you are expecting and include the output from the output window.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #48
        Hi Koganam,

        These are level 5 points using true high/true low values to determine the pivots.

        The green and red lines are qualified breakouts, which extends from the initial 2 points, while the magenta line is a disqualified breakout and the dashed blue lines are unqualified lines

        Regards

        Kay Wai

        Comment


          #49
          Hi Chelsea,
          I’m using my own data source for daily data and I’m in the UTC + 8 timezone. Session template for dataseries is 24/7.

          Keeping the discussion to the 4 circles in the earlier chart, I expect lines to be drawn between:

          1) Jan 9 2016 to Jan 14 (the last price bar is Jan 16): Data for DemandPointb for the line drawn from Dec 30 2015 to Jan 9 2016 only starts showing up on Jan 13, 2016 – 2 days after the bar should have been drawn. Reason could be COBC = true. But why does the data still show on Jan 14 and Jan 15 instead of resetting? The point on Jan 9 could not be used for DemandPointa because DemandPointa > 0 at that time.

          2)Dec 5 2015 and Dec 11: DemandPointb for line drawn from Nov 26 to Dec 3 only populated on Dec 5. Reason: COBC = true. Data stays for another day instead of resetting.

          3)Oct 24 2015 to Nov 5: No line drawn because values were still stored in DemandPointa and DemandPointb for line drawn from Oct 10 to Oct 16.

          4)Oct 16 2015 to Oct 24: Value for DemandPointb only populated on Oct 20. Reason: COBC = true. Data stays for 6 days before resetting.

          These are the observations from the output that I’ve made. It does explain why there were no lines drawn on those particular dates. Any suggestions on how I can rectify the situation? I’ve appended the data file so that only the relevant data for discussion is attached.

          Regards

          Kay Wai
          Attached Files

          Comment


            #50
            Hello Kay,

            Have you removed the previous print that I have suggested you add? This one shows on which bars items are being drawn.

            The prints showing on which bars the condition is true should print on every bar. The prints showing when the drawing is triggered and the bars ago values used should appear only when the condition to draw the line is true.

            There is no data for Jan 16th in the second file.

            Looking at December 5th you are expecting a line drawn from 2 bars ago to 8 bars ago, is this correct?

            From the first output file:
            12/8/2006 1:00:00 PM | DemandPointa: 3.5365

            From the second output file:
            12/5/2015 1:00:00 PM | TL[1]: 4.2115 < TL[0]: 4.1892 && TL[1]: 4.2115 < TL[2]: 4.207 && DemandPointa: 4.1873 > 0 && DemandPointb: 4.207 > 0

            On December 5th, no line was drawn because all of the conditions did not evaluate as true.
            TL[1]: 4.2115 < TL[0]: 4.1892
            The TL series from one bar ago, is not less than the current bar. No line will be drawn on the 5th.

            12/8/2015 1:00:00 PM | TL[1]: 4.1892 < TL[0]: 4.194 && TL[1]: 4.1892 < TL[2]: 4.2115 && DemandPointa: 4.1873 > 0 && DemandPointb: 4.207 > 0

            This part is odd. The condition shows that the condition to draw should be true. We should see the start bars ago value and end bars ago value print.
            However, its as if the output.txt file does not match the output1.txt file.

            The print in output.txt shows:
            12/8/2006 1:00:00 PM | DemandPointa: 3.5365

            My guess is this is the print from the following condition:
            else if ((DemandPointa > 0) && (DemandPointb == 0) && (TDTrueLow().TL[1] < DemandPointa))
            {
            DemandPointa = TDTrueLow().TL[1];
            Print(DemandPointa);
            startbarsago = CurrentBar;
            }

            If this condition triggers, then the line will not be drawn. This is because you are using else ifs, meaning if one condition above evaluates as true, the condition to draw the line will not be checked.

            The output1.txt file shows that condition could not have evaluated as true. The part with '&& (DemandPointb == 0)' would have prevented that condition from evaluating as true as at the time the print shows DemandPointb had a value of 4.207.

            The output.txt suggests that this condition was true and the line was not drawn. The output1.txt suggests that the line would have been drawn.

            Because the first prints that created output.txt have been removed, this is not clear in the output1.txt file by itself and this would be very helpful to understand why a line did or did not draw.
            This means I attempted to use both files to get a clear picture of what is evaluating, but the two files do not seem to agree as if either the code or data has changed in-between the creation of the files.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #51
              Originally posted by kaywai View Post
              Hi Koganam,

              These are level 5 points using true high/true low values to determine the pivots.

              The green and red lines are qualified breakouts, which extends from the initial 2 points, while the magenta line is a disqualified breakout and the dashed blue lines are unqualified lines

              Regards

              Kay Wai
              I have taken another look at the Bloomberg output and think that I may see what is happening. Jason Perl's description was not wrong; it was just incomplete. It would appear that when a supply line (for example) is violated, the code draws another line connecting the most current swing to the immediate previous swing at the same level, no matter how far back, or any intervening swings, and leaves the violated line in place. Perl did not make that quite clear, and seemed to imply that one only looked at the last 2 adjacent qualifying levels, rather than the last 2, no matter how far separated.

              Given that understanding, yes, you are going to have to use some collection and loop back every time a new swing develops. A dictionary or hashtable would probably be the most efficient, but a simple Generic List would probably be easier to actually code. As I am no longer really using D*Marks's methods, I doubt that I have the time to tackle this as a free project. I apologize.

              Comment


                #52
                No Worries Koganam. Thx for your pointers! Kay Wai

                Comment


                  #53
                  Hi Chelsea,

                  Sorry I misread your instructions. I’ve attached what I think you are looking for.

                  There doesn’t seem to be any consistency on when a line is drawn after both points are determined. Is there something wrong with the way I wrote the code?

                  There is no data for Jan 16 in the output file because the bar isn’t “closed” yet.

                  Because of COBC = true, the demandpoint can only be determined 2 bars after a potential demandpoint has been identified. With TL[1] < TL[2] && TL[1] < TL[0], TL[1] can only be a demandpoint after TL[0] has closed. This is less than ideal and will have to do till I learn of a better way to code this.

                  Regards

                  Kay Wai
                  Attached Files

                  Comment


                    #54
                    Hi Kai,

                    With the output1.txt file from your last post I am able to see that a line should have been drawn on December 8th.

                    12/8/2015 1:00:00 PM | TL[1]: 4.1892 < TL[0]: 4.194 && TL[1]: 4.1892 < TL[2]: 4.2115 && DemandPointa: 4.1873 > 0 && DemandPointb: 4.207 > 0
                    12/8/2015 1:00:00 PM | start bars ago: 8 | end bars ago: 3

                    I am not certain of the exact dates without the session template, but it should be drawn from 8 days ago (excluding weekends this would be the 26th or 27th of Nov) to 3 bars ago (excluding weekends this would be Dec 3rd).

                    I am able to see this line in your screenshot.

                    I had to look back at your post #49 because I was looking at this as a line you are expecting to be drawn that was not drawn.
                    This means I was looking at this incorrectly. There should be a line from Dec 5 to Dec 11th. The information I am missing is, what day should that have been drawn on?

                    In post #47, I had set the font to bold on the following because I needed both pieces of information.
                    On what bar date are you expecting the line to be drawn?
                    When this triggers on what bar should the start point be and the end point be?


                    What I am missing is what day that should be drawn.

                    You mention in post #53 that this should be drawn 2 days after the trend.
                    This would be Dec 10th.

                    12/10/2015 1:00:00 PM | TL[1]: 4.215 < TL[0]: 4.254 && TL[1]: 4.215 < TL[2]: 4.194 && DemandPointa: 0 > 0 && DemandPointb: 0 > 0

                    For the Dec 10th bar the second part of the condition was not true.
                    TL[1]: 4.215 < TL[2]: 4.194
                    4.215 is not less than 4.194
                    This means the nested if statement inside that is looking for DemandPointa and DemandPointb to be greater than 0 was not checked.

                    Further, had DemandPointa and DemandPointb been checked, these would have been 0 and this would still not have drawn a line.

                    On Dec 8th a line was drawn. Any time a line is drawn DemandPointa and DemandPointb are reset to 0 which would prevent a line from being drawn until another bar or bars after this point triggers both of these values to be set again to something higher than 0.

                    So, do you want to be resetting these when a line is drawn? It requires a few bars to set a trigger for the next line to be drawn.

                    Even if these two variables are reset and they have values greater than 0, you still need TL[1] to be less than TL[2] for the line to be drawn.
                    Are you expecting TL[1] to have a lower value?
                    Are you expecting TL[2] to have a higher value?
                    Last edited by NinjaTrader_ChelseaB; 01-28-2016, 11:26 AM.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #55
                      Hi Chelsea,

                      Referring to post #49, the first line that was not drawn, was from Jan 9 to Jan 14 2016. The start bars ago is 4 while the end bars ago is 1. (The “barsago” in drawline have a +1 added to it for both start bar and end bar. The line before that which we see on the chart and output1 drew on Jan 15, 2016. The starting bar, dated Dec 30 2015 and ending bar on Jan 9, was determined on Jan 1 2016 and Jan 13 2016 respectively. Jan 10 and 11 are weekends for chart purposes. If the line from Jan 9 to Jan 14 were to be drawn, it would’ve been drawn on Jan 16 – the current bar on the chart. However this is unlikely to occur as DemandPointa and DemandPointb have not reset. What I don’t understand is why the Dec 30 to Jan 9 line only drew on Jan 15 even though DemandPointb was confirmed on Jan 13. The latest it should have drawn was on Jan 13 but it was only drawn on Jan 15. From output1, you will note that there are values for DemandPointb on Jan 13, 14 and 15 and these values are the same. Even if the DemandPoints were to have reset, it is unlikely that the Jan 9 to Jan 14 line would have been drawn because of the “lag” effect. All the black squares (these are stored in the dataseries) in the chart potentially can have lines drawn through them IF the points before it are less than it.

                      The second line that wasn’t drawn is from Dec 5 to Dec 11 2015. The line that was drawn before it was Nov 26 2015 to Dec 3. DemandPointb would have been determined on Dec 5 due to COBC = true. Had the line been drawn on Dec 5 and the DemandPoints resetted, it should have been possible (technically) to determine DemandPointa on Dec 9 for Dec 5 start point. (Dec 6 and 7 are weekends for chart purposes). The end point should have been determined on Dec 15 and drawn on Dec 11 (Dec 13 and 14 are weekends), with a line drawn from Dec 5 to Dec 11. Why didn’t the line draw on Dec 5 instead of Dec 8? The next question is would the line which is currently drawn from Dec 11 to Dec 19 be drawn? Theoretically it wouldn’t have been possible as the resets would only have occurred on that bar itself.

                      The third line that wasn’t drawn is from Oct 24 to Nov 5. And the fourth line is from Oct 16 to Oct 24. The line that was drawn prior to these lines is Oct 10 to Oct 16. The starting point (DemandPointa) for this line was determined on Oct 14 (Oct 11 and 12 are weekends). DemandPointb was determined on Oct 20 (Oct 18 and 19 are weekends) but only drew on Oct 27 instead of Oct 20. There was no way the third missing line or fourth missing line could have been drawn as a result. Had it drawn the line on Oct 20 and resetted, the possibility of the Oct 24 to Nov 5 line being drawn would be almost a certainty. But the line from Nov 5 to Nov 12 would not have been drawn.

                      Ideally I would like the lines to be drawn as the attached chart. I would also have preferred to use the DataSeries in the indicator but as there is zero values on some bars, I am not confident of drawing lines from the DataSeries. I've also added dates to the charts.

                      Regards

                      Kay Wai
                      Attached Files

                      Comment


                        #56
                        Hello Kay,

                        The line drawn from Jan 9th to Jan14th would have been drawn on Jan15th and not the 16th correct?

                        The output file does not have any prints for Jan16th. I skipped this, because the bar for this would not be closed.

                        If the bar has not closed, and the script is running with Calculate on bar close, then the code would not have been evaluated and nothing would be drawn.

                        Unless there is a print for that day, there isn't going to be a drawing object drawn on that day.

                        But we can focus on the item from the 15th. This object drawn on the 15th was drawn because on the 13th the conditions were not met to draw.

                        1/13/2016 1:00:00 PM | TL[1]: 4.3805 < TL[0]: 4.3755 && TL[1]: 4.3805 < TL[2]: 4.3472 && DemandPointa: 4.2645 > 0 && DemandPointb: 4.3472 > 0

                        4.3805 is not less than 4.3755 so no drawing object would be drawn.

                        On the 14th the conditions again were not met.

                        1/14/2016 1:00:00 PM | TL[1]: 4.3755 < TL[0]: 4.3715 && TL[1]: 4.3755 < TL[2]: 4.3805 && DemandPointa: 4.2645 > 0 && DemandPointb: 4.3472 > 0

                        4.3755 is not less than 4.3715 so no drawing object would be drawn.

                        On the 15th the conditions are met.

                        1/15/2016 1:00:00 PM | TL[1]: 4.3715 < TL[0]: 4.3772 && TL[1]: 4.3715 < TL[2]: 4.3755 && DemandPointa: 4.2645 > 0 && DemandPointb: 4.3472 > 0

                        And a line is drawn.

                        On the 13th are you expecting TL[1] to have a lower value? Are you expecting TL[0] to have a greater value?

                        On the 14th are you expecting TL[1] to have a lower value? Are you expecting TL[0] to have a greater value?
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #57
                          Hi Chelsea,

                          I think I understand what you are saying! Lemme play around with the code a bit to see how I go.

                          Thanks again!

                          Kay Wai

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by algospoke, Yesterday, 06:40 PM
                          2 responses
                          23 views
                          0 likes
                          Last Post algospoke  
                          Started by ghoul, Today, 06:02 PM
                          3 responses
                          14 views
                          0 likes
                          Last Post NinjaTrader_Manfred  
                          Started by jeronymite, 04-12-2024, 04:26 PM
                          3 responses
                          45 views
                          0 likes
                          Last Post jeronymite  
                          Started by Barry Milan, Yesterday, 10:35 PM
                          7 responses
                          22 views
                          0 likes
                          Last Post NinjaTrader_Manfred  
                          Started by AttiM, 02-14-2024, 05:20 PM
                          10 responses
                          181 views
                          0 likes
                          Last Post jeronymite  
                          Working...
                          X