Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw Extended Line Indicator

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

    Draw Extended Line Indicator

    Hi,
    Is there any way to write an indicator that will draw and extended line between 2 points (say the Close[28] and Close[0] and capture the value of that line for a future bar condition?
    I want to use it in a strategy I've written. For instance, lets say I need an extended line drawn between the Close at 14:15 EST yesterday and the Close at 08:00 EST this morning. (I can draw this line in the Strategy, but there are no values to it.)
    Once the line is drawn, it stays put. I need to be able to access the value of that line sometime in the future. For instance, If Time > 09:30 EST and Close[0] < Extended line value then Enter Short.

    I'm terrible building indicators and have been through all the tutorials but can't find any example that's close. DrawExtendedLine is a drawing command and not an indicator so I can't even open it up to see how it's done.

    Suggestion, Help, Guidance, Advice??
    Thanks much,
    Joe

    #2
    Trade1953, this is possible, but not without a bit of coding. You will basically have to draw the line and then reference the points of the line to run some calculations. The form of a line is y = mx + b, where y is price, m is the slope (change in price over change in bars), and b is the initial offset. For the first point of the line, the change in bars is 0, so you can find the offset, which is equal to the price.

    From there, you can divide the change in price between the two points by the number of bars between the points to get the slope. You can then take the initial offset and for every bar you move over, add the slope (so for 5 bars, and a slope of 2, that would y = 2 * 5 + b). This will give you the price of the line at any point after the initial point.
    AustinNinjaTrader Customer Service

    Comment


      #3
      Thanks Austin,
      That's taking me back quite a few years to the old algebra days. Now if I can find out how to make an indicator that draws a line between 2 points, I can then do the math part.
      There just isn't any good samples in Ninja Help about building complex indicators (or a simple one for drawing a line for that matter).
      I'll keep your reply handy and I thank you very much for your detailed answer!
      Joe

      Comment


        #4
        Joe, you can draw a line with the DrawLine() method.

        This code will draw a line from 10 bars back to the current bar from a price of 1000 to a price of 1001.
        Code:
        // Draws a dotted lime green line from 10 bars back to the current bar
        // with a width of 2 pixels
        DrawLine("tag1", false, 10, 1000, 0, 1001, Color.LimeGreen, DashStyle.Dot, 2);
        AustinNinjaTrader Customer Service

        Comment


          #5
          Hey Austin,
          Yes, I already used that in the strategy and it draws the extended line where I need it. There just isn't a value to work with on the line anywhere and I don't know how to program an indicator that draws an extended line and produces values that the strategy can see. (I had tried to make an Indie that just uses DrawExtendedLine but it didn't work, because I don't know what I'm doing with Indies.)

          BUT, it dawned on me while making coffee this morning that I DON'T NEED an indicator for the strategy to fire off of. You gave me the answer, but I didn't see it. My mindset was that I needed an Indicator, but I don't! You put me so close that if it had been a snake it would have bit me!

          So, I'll just program my own extended line in the Strategy itself. I know the value of Close X bars ago, and Close Current Bar. With the formula you reminded me of I can calculate the slope and get the line value each bar into the future just as you suggested. I kept thinking I had to program this in an Indicator.

          Thank You very, very much!! I hope I can "pay it forward" one day!
          Joe

          Comment


            #6
            Slope formula

            Hi guys, thanks for posting on this. I have one further issue I was hoping someone could throw light. Attached is a chart for CL. I am trying to work out the distance in ticks the close of the current bar is away from the upper channel trendline.

            I worked out the slope as 0.13513 based on the following:


            start Price 104.982
            Finish price 107.924
            Bars 28

            I know that each trendline point increased by 0.13513 but wondering how to calculate the actual trendline value of the current bar based on this data. I want to do something like this:

            if uppertrendlinevalue [0] - Close [0] <= 5 * TickSize.

            {do something}

            I'm assuming it is something like the opening price of 104.982 x 0.13513 x the number of bars elapsed since the start bar to current bar. Not sure how to do it though.



            Cheers
            DJ
            Attached Files

            Comment


              #7
              Originally posted by djkiwi View Post
              Hi guys, thanks for posting on this. I have one further issue I was hoping someone could throw light. Attached is a chart for CL. I am trying to work out the distance in ticks the close of the current bar is away from the upper channel trendline.

              I worked out the slope as 0.13513 based on the following:


              start Price 104.982
              Finish price 107.924
              Bars 28

              I know that each trendline point increased by 0.13513 but wondering how to calculate the actual trendline value of the current bar based on this data. I want to do something like this:

              if uppertrendlinevalue [0] - Close [0] <= 5 * TickSize.

              {do something}

              I'm assuming it is something like the opening price of 104.982 x 0.13513 x the number of bars elapsed since the start bar to current bar. Not sure how to do it though.



              Cheers
              DJ
              Code:
              double TrendLineValueAtCurrentBar = StartBar + slope * (CurrentBar - StartBar);

              Comment


                #8
                DJ,
                Let me know if that doesn't work for you for some reason and I'll send you the code. I have it working perfectly in one of my strats. Should be no problem having it do "something" when it gets within 5 tics of the line.
                Joe

                Comment


                  #9
                  Trend

                  Hi guys, thanks for the quick responses. Well, I have spent 4 hours on this and it has me beat so far so Joe would love some some advice or code to view on how to achieve this.

                  Cheers
                  DJ

                  Comment


                    #10
                    Originally posted by djkiwi View Post
                    Hi guys, thanks for the quick responses. Well, I have spent 4 hours on this and it has me beat so far so Joe would love some some advice or code to view on how to achieve this.

                    Cheers
                    DJ
                    What could you not get working with the line that I provided, if I may ask?

                    Comment


                      #11
                      Start Bar

                      Hi Koganam

                      Thanks for posting, well I was not sure what to put exactly in the formula.

                      double TrendLineValueAtCurrentBar = StartBar + slope * (CurrentBar - StartBar);
                      I'm not sure what the startbar value is. I think that should be the starting price instead of start bar? I think it needs to be starting price+slope * (Current bar less StartBar).

                      Thanks
                      DJ

                      Comment


                        #12
                        Originally posted by djkiwi View Post
                        Hi Koganam

                        Thanks for posting, well I was not sure what to put exactly in the formula.

                        double TrendLineValueAtCurrentBar = StartBar + slope * (CurrentBar - StartBar);
                        I'm not sure what the startbar value is. I think that should be the starting price instead of start bar? I think it needs to be starting price+slope * (Current bar less StartBar).

                        Thanks
                        DJ
                        You wrote this:

                        I worked out the slope as 0.13513 based on the following:


                        start Price 104.982
                        Finish price 107.924
                        Bars 28
                        I took that as the jumping off point, assuming that you must have recorded the "start Price". You merely need to record the bar number at the "start Price": that would be the StartBar.

                        Maybe the correct question to ask, is how did you record the "start Price" that you are using? If you posted your code, maybe, we can just correct it?

                        Comment


                          #13
                          Code Issues

                          Hi Koganam, good idea let me post some numbers and code. For starters let me explain what I'm trying to achieve as there maybe an easier way. If you look at the chart attached, it shows a channel. So I want to know the top of the current top of the channel line about channel about 856 and bottom is 831 and insert a signal when it gets close. I have no problems doing this for a horizontal line but upward sloping line like this you need to calculate the slope to get the upper points.

                          Now the data points on the top lines to work out the slope is start price of 813.12 and finish 849.22 (See the first and third dots on the line). If I count the number of bars from the first data point to the second it is 39 bars which gives a slope of 0.23461.

                          So I have put the following code in ninja which gives a result of 814.41 which makes no sense as it should be about 856 which is the top of the line. I'm obviously doing something seriously wrong somewhere. Any ideas on this one? Thanks. DJ

                          #region Variables

                          private double Opening =813.12 ;
                          private double slope =0.023461 ;
                          private int StartBar =39 ;

                          protected override void OnBarUpdate()

                          double ResistanceValue = Opening + slope * (CurrentBar - StartBar);

                          {
                          DrawTextFixed("Uppertrend","Resistance: "+ResistanceValue.ToString("N2"), bPosition,Color.White,textFontMed, Color.Black, Color.Red, 10);
                          Attached Files

                          Comment


                            #14
                            DJ,
                            Here's a doc with my code in it and some explanation. Now that I see what your are trying to do I'll play around a little too. My code does all the calculations for you but uses the values of a Bar (open, high, low, close) to get the 2 points to draw a trend line. It then calculates the value of the trend line as each bar closes. Don't know if it's what you need but It still might give you some ideas.
                            Joe
                            Attached Files

                            Comment


                              #15
                              Hi,
                              What is the difference btw. DrawLine and DrawExtendedLine?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              636 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              366 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              107 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              568 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              571 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X