Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help with Formula to Find Trend Channel Midpoint

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

    Help with Formula to Find Trend Channel Midpoint

    I can't seem to figure out the correct formula to find the y-intercept of a Trend Channel. I've looped through the levels and gotten anchor points of the trendLevel (0 value) and parallelLevel (100 value) and applied the formulas for slope and y-intercept I found in 'YaxisProjectionofLine' sample script and this from forum post:
    Code:
                                 slope between anchors = (anchor2price - anchor1price) / (anchor2bar - anchor1bar)
                                   (slope = (y2 - y1)/(x2 - x1))
    
                                 yintercept = slope * (CurrentBar - anchor1bar)
                                    (yintercept = slope * (x2 - x1))​
    Without having anchor point for midpoint I'm pretty sure I need to take the range and divide by 2. I know it's not correct code and won't hold if anchor points are inverted, etc. This is what I have:
    Code:
                                    x1bbar = Bars.GetBar(subWave.TrendStartAnchor.Time);
                                    y1 = subWave.TrendStartAnchor.Price;
                                    y2 = subWave.TrendEndAnchor.Price;
                                    y3 = subWave.ParallelStartAnchor.Price;
                                 [B]   y4 = (y1 - y3) / 2 + y3; // this is trying to figure midpoint (50 Value)[/B]
                                    x1 = CurrentBar - Bars.GetBar(subWave.TrendStartAnchor.Time);
                                    x2 = CurrentBar - Bars.GetBar(subWave.TrendEndAnchor.Time);
                                    x3 = CurrentBar - Bars.GetBar(subWave.ParallelStartAnchor.Time);
                                    x2bbar = Bars.GetBar(subWave.ParallelStartAnchor.Time);
                                    
    
        
                                // First calculate the slope of trend channel
                                trendSlope = (subWave.TrendEndAnchor.Price - subWave.TrendStartAnchor.Price) / (Bars.GetBar(subWave.TrendEndAnchor.Time) -                              Bars.GetBar(subWave.TrendStartAnchor.Time));
    
    ​
    ​
                                // Now project the slope to a new bar
                                yintercept = trendSlope * (CurrentBar - x1bbar);
                                yinterceptParallel = trendSlope * (CurrentBar - x2bbar);
                               [B] yinterceptMid = ???[/B]
    
                                // To demonstrate that we know where the trend channel line is
                                Draw.Dot (this, "t1"+CurrentBar, true, 0, yintercept + y1, Brushes.Gold);
                                    
                                // To demonstrate that we know where the parallel channel line is
                                Draw.Dot (this, "t5"+CurrentBar, true, 0,  yinterceptParallel + y3, Brushes.Gold);
                                    
                                    // To demonstrate that we know where the mid channel line is
                                Draw.Dot (this, "t6"+CurrentBar, true, 0, [B]trendSlope * (y1 - y3) / 2 + y3[/B], Brushes.Gold);​​
    Attached Files

    #2
    Hello swjake,

    Thank you for your inquiry.

    To clarify, are you wanting to calculate the midpoint, and then calculate an intercept at some point between start and end of the price levels? Are you trying to get the intercept for a specific bar within that range, or the most recent bar which is CurrentBar?

    I look forward to your response.

    Comment


      #3
      Good Morning Gaby,

      I'm trying to get the yintercept for the midpoint @ the CurrentBar. The formula I worked up--and it's working so far and I'm somewhat in disbelief-- is:

      Code:
      (subWave.TrendStartAnchor.Price - subWave.ParallelStartAnchor.Price) / 2 + subWave.ParallelStartAnchor.Price = y4
      Which gives me midpoint "start anchor" and then I apply slope (yinterceptParallel + y4)

      So far if holds in upslope & downslope and inverted. But it doesn't seem quite right...

      Any suggestions or feedback is appreciated.

      Thanks!

      Comment


        #4
        Hello swjake,

        Can you please clarify what specifically seems not quite right? The image you posted seems to show a dot drawn on the CurrentBar/midline with the calculations you did.

        If you are confused why your formula works, we recommend you print out the values and then manually do the math to see what values are being generated based on your formula.

        Please let us know if we can assist further.

        Comment


          #5
          Thanks NinjaTrader_Gaby. I thought there might be a cleaner formula, but this works.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          56 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          133 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          73 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          45 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          49 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X