Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Does current bar touch or cross my trendline?

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

    #31
    Chelsea B, I'm very, very appreciative for your help thus far. I think I am almost there.

    The yintercept is giving me very small numbers. Can you check my math here? I'm not understanding how the below gives me the yintercept.

    double trendSlope = (channel.TrendEndAnchor.Price - channel.TrendStartAnchor.Price) / (Bars.GetBar(channel.TrendEndAnchor.Time) - Bars.GetBar(channel.TrendStartAnchor.Time));
    double yintercept = trendSlope * ((CurrentBar-1) - Bars.GetBar(channel.TrendStartAnchor.Time));

    Output:

    Tag: Trend channel 15 Start Price: 3674.75832167832 End Price 3671.35916083916 Start Bars Ago: 3607 End Bars Ago: 3611 Slope: -0.849790209790285 yintercept: -1.69958041958057
    Last edited by shildebrand324; 12-10-2020, 08:32 PM.

    Comment


      #32
      Anyone around today?

      Comment


        #33
        Hello shildebrand324,

        Do you still see the problem if you use the following calculation instead? If that is not a solution could you attach another small excerpt of the output and logic used?

        double yintercept = trendSlope * Bars.GetBar(channel.TrendStartAnchor.Time) - channel.TrendStartAnchor.Price;

        I look forward to being of further assistance.

        Comment


          #34
          Still no luck...don't I need the current bar somewhere to see if it crossed the yintercept?


          Here's the print output:

          Tag: Trend channel Start Price: 3632.39289017421 End Price 3648.13162777306 Start Bars Ago: 3487 End Bars Ago: 3501 Slope: 1.12419554277497 yintercept: -163.450039085016

          Here's the loop:

          foreach (DrawingTool draw in DrawObjects)
          {
          if (draw is DrawingTools.TrendChannel)
          {
          TrendChannel channel = draw as DrawingTools.TrendChannel;
          double parallelEndAnchorPrice = channel.ParallelStartAnchor.Price + (channel.TrendEndAnchor.Price - channel.TrendStartAnchor.Price);
          int parallelEndAnchorBar = Bars.GetBar(channel.ParallelStartAnchor.Time) + (Bars.GetBar(channel.TrendEndAnchor.Time) - Bars.GetBar(channel.TrendStartAnchor.Time));
          double trendSlope = (channel.TrendEndAnchor.Price - channel.TrendStartAnchor.Price) / (Bars.GetBar(channel.TrendEndAnchor.Time) - Bars.GetBar(channel.TrendStartAnchor.Time));
          double yintercept = trendSlope * ( Bars.GetBar(channel.TrendStartAnchor.Time) - channel.TrendStartAnchor.Price);



          Print("Tag: " + draw.Tag + " Start Price: " + channel.TrendStartAnchor.Price + " End Price " + channel.TrendEndAnchor.Price + " Start Bars Ago: " + Bars.GetBar(channel.TrendStartAnchor.Time) + " End Bars Ago: " + Bars.GetBar(channel.TrendEndAnchor.Time) + " Slope: " + trendSlope + " yintercept: " + yintercept);


          }
          }

          Comment


            #35
            Okay, so I'm totally confused on how this gets me the y intercept, based on the equation below, based on the data generated from chart.
            The y intercept seems too low for me to compare the close of the current bar price to see if it crossed. What am I missing?

            Print output:
            Trendline Start Anchor Price: 3632.4458825567
            Trendline End Anchor Price 3646.06492485604
            Trendline Start Bars Ago: 3444
            Trendline End Bars Ago: 3456
            Current Bar: 3451
            Slope: 1.13492019161182
            yintercept: 7.94444134128272


            Calcs
            slope between anchors = (anchor2price - anchor1price) / (anchor2bar - anchor1bar)
            (slope = (y2 - y1)/(x2 - x1))
            (slope = (3646 - 3632) / (3456 - 3444))

            yintercept = slope * (CurrentBar - anchor1bar)
            (yintercept = slope * (x2 - x1))
            (yintercept = 1.13 * (3451 - 3444))

            Then you can check if the yintercept is equal to the current bar close, or within a tick or within the high and low, or whatever you would like
            Last edited by shildebrand324; 12-12-2020, 02:34 PM.

            Comment


              #36
              So, figured out I had to take the yintercept and add it to the start anchor price to get the projection.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              595 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              343 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              103 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              556 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              554 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X