• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

X/Y for Close[0]

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

    X/Y for Close[0]

    I've been having a hard time finding a clear answer for this, so I figured I'd just ask directly. If we can do something like:

    TrendChannel tc = Draw.TrendChannel(...);

    double x1 = tc.TrendStartAnchor.GetPoint(ChartControl, ChartPanel, this.chartScale, false).X;
    double y1 = tc.TrendStartAnchor.GetPoint(ChartControl, ChartPanel, this.chartScale, false).Y;

    to get the (x, y) coordinates of that anchor, how do we do the same thing for the current (x, y) position of Close[0] on a given chart?

    Thanks in advance!

    #2
    Hello, Thanks for your post.

    A good indicator to look at would be the PriceLine indicator They keep three plots for the bid, ask, and last prices and use the OnMarketData override to fill the plots with values. In the OnRender method of this indicator, they get the y coordinate from the plot value for the last close price.at line 122 of the script.

    Kind regards.
    Last edited by NinjaTrader_ChrisL; 07-18-2019, 08:13 AM.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      I made currentY global and then added:

      protected override void OnRender(ChartControl chartControl, ChartScale chartScaleIn)
      {
      this.chartScale = chartScaleIn;
      this.currentY = this.chartScale.GetYByValue(Close[0]);
      base.OnRender(chartControl, this.chartScale);
      }

      When I check the value of the Y position, it shows -3497 when it should be about 161 based on the Y position of some other points I have on the chart. I had previously found GetYByValue, but got similar results to this instead of what I was expecting.

      Comment


        #4
        Hello, thanks for your reply.

        The price series arrays can not be used within OnRender. Use GetValueAt instead. The section titled "barsAgo indexer vs. absolute bar Index" explains the difference:
        https://ninjatrader.com/support/help...#Errorhandling

        GetValueAt(CurrentBar) would provide the most current value of the series.

        Kind regards.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Worked great!

          I did:

          protected override void OnRender(ChartControl chartControl, ChartScale chartScaleIn)
          {
          this.chartScale = chartScaleIn;
          this.currentY = this.chartScale.GetYByValue(GetValueAt(CurrentBar) );
          base.OnRender(chartControl, this.chartScale);
          }

          And this.currentY is now within the range that I was expecting. Thanks for the help.

          Comment


            #6
            Ok, I spoke too soon. I've left it running today, and found that it's consistently out of range. I'm checking it's Y distance between two anchor points. The top anchor is at Y = 241, the bottom anchor is at Y = 122, and the code we were working on is saying Y = 27 for the current bar. However it's actual Y position is between the two anchors. How is it so far off?

            Comment


              #7
              Hello, Thanks for your reply.

              I made a script that will follow the current price of the instrument. We need to keep track of the current price in OnMarketData, so I made a class-level variable to hold the current price and use that in OnRender. Place the attached file within Documents\NinjaTrader 8\bin\Custom\Indicators then compile.

              Please let me know if you have any questions.
              Attached Files
              Chris L.NinjaTrader Customer Service

              Comment


                #8
                I tried both methods and they're both off. Here's two examples of what I'm looking at. One was the first suggested change using CurrentBar. The second is the method used in the test.cs.

                In the first, we can see that the Y position for the top anchor is 337, and the bottom is 210 making them 127 units apart. The current bar is about 75% up from the bottom anchor. This would make it about 305 for the Y position. However, we see that using this.currentY = this.chartScale.GetYByValue(GetValueAt(CurrentBar) ); we get 225. This is way off by these standards.

                Next we see with the second method. Top anchor is 310, bottom is 183 making it 127 units apart again. The current bar is about halfway between the two making it about 246. It's calculated as 225. It's closer than the previous method, but still wrong.

                I'm not sure what else we can do at this point.

                Comment


                  #9
                  Hello learningnt, thanks for your reply.

                  I am not clear on what exactly is wrong. Are the values of your trend channel not correct? In that case it would be a question of what your (x,y) vectors are and why those are not producing the expected result.
                  Chris L.NinjaTrader Customer Service

                  Comment


                    #10
                    Hi Chris,

                    It's my understanding that we draw the trendchannel from top down, and right to left. This puts the start anchor at the top right. I used this:

                    double y1 = tc.TrendStartAnchor.GetPoint(ChartControl, ChartPanel, this.chartScale, false).Y;

                    to get the Y coordinate for that anchor. I do collect the X for that as well along with getting the X/Y for the end anchor. I used ParallelStartAnchor, and a little math for the other point since ParallelEndAnchor doesn't exist anymore(it's in the docs, just not in the editor), to determine the anchors for the other line. Is this not a good way to get their X and Y coordinates?

                    Comment


                      #11
                      Hello learningnt, thanks for your reply.

                      I do not see this ParallelStartAnchor property in our NT7 documentation. If you could direct me to more info on that it would be appreciated. Can I confirm that the problem is you are not getting correct values for your trend channel start and endpoints? If so please share what they actually are and what they should be (along with some formula for the calculation)

                      If possible please Export your script and send it to me at platformsupport at ninjatrader.com, referencing "Attn ChrisL 2216311 <forum thread link>" in the body of the email.

                      I look forward to hearing from you.
                      Chris L.NinjaTrader Customer Service

                      Comment


                        #12
                        Hi Chris,

                        This is in NT8, but I've added the documentation link that you requested below. At this point, I don't know which ones are wrong. However, based on the information that I've looked at, the anchors seem to be correct. I'm always open to a new pair of eyes to look at it.

                        https://ninjatrader.com/support/help...endchannel.htm

                        I'll send a copy of the script once I get home this evening.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Newtrader101, Today, 03:54 PM
                        1 response
                        15 views
                        0 likes
                        Last Post NinjaTrader_ShawnB  
                        Started by williamzz, Today, 03:28 PM
                        0 responses
                        7 views
                        0 likes
                        Last Post williamzz  
                        Started by Robert87, Today, 11:07 AM
                        0 responses
                        13 views
                        0 likes
                        Last Post Robert87  
                        Started by phta123, Today, 10:24 AM
                        0 responses
                        17 views
                        0 likes
                        Last Post phta123
                        by phta123
                         
                        Started by sidviciousX, Today, 06:47 AM
                        0 responses
                        16 views
                        0 likes
                        Last Post sidviciousX  
                        Working...
                        X