Does anyone what equation/formula is used to determine that pink upper line?

For detecting channel lines, it was a bit easier, where I've used a regression line, along with 2 standard deviation lines.

I'm not sure what tags to mark this question under.


It is a trend line. It is made by drawing a line through three local maxima or minima that happen to lie on a line where most data is below/above the line, respectively. There doesn't seem to be an elegant formula used for finding them.

A randomized approach could be: You could find all the local maxima in your window and repeatedly select three points, testing to see how well a line fits them and how often the prices go above the line, and pick the best one.

A deterministic approach could be: Find the convex hull of your data. Each segment on the hull can be extended in either direction to be a trend line that touches at least two points. Additionally, all points are guaranteed to lie on one side of each of these lines. Choose the line that touches the most points (you can keep track of how many data points each line touches while you're running the convex hull algorithm). Graham scan or the gift-wrapping algorithm will work. You do run into the problem of having to choose your window, but you can solve this buy running the algorithm for multiple window offsets and selecting the best from all of them.

There can be multiple possible trend lines per window, and it is scale-dependent. The blue line in that picture is also a trend line.

  • $\begingroup$ Is it possible to just determine a line where all the points lie beneath it without needing to determine all the maximas? $\endgroup$ – user172839 Nov 27 '17 at 7:21
  • $\begingroup$ @user172839 Yes. You can find the convex hull of your data points. Each segment of the convex hull would be a segment of a line that goes over/under all the data. They would only be guaranteed to go through two points, though. $\endgroup$ – WhatToDo Nov 27 '17 at 7:30
  • $\begingroup$ Thank you for such a detailed response. I'll take a look $\endgroup$ – user172839 Nov 27 '17 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.