How to draw a line to fit bars in the best possible way

jackpotcity

New member
Joined
Nov 28, 2018
Messages
9
Hello!

I have a question that I am trying to figure out how to do and thinking of that there must be a mathematical solution to do this.
If I need to put down all the values for the green bars. I can do that? Otherwise is there an example of what approach that should be used to solve this?

The problem is as follows:
As seen in the image, I have a stockchart with some green bars. For example the first green bar has a low value of 100$ and a high value of 110$ which means that the bars length is 10%. And so on for all the bars.

1. Now I want to draw a red line on top of the green bars so the line is as high as possible AND touches as many green bars as possible at the same time.
The line should then allow green bars to be able to stick up over the red line with let us say maximum 1% to find the best fit to touch as many green bars as possible.

2. Exactly the inverse should then happen to the lower red line where the line is as low as possible AND touches as many green bars as possible at the same time.

But I think If I could understand how do this mathematically for the first red line on top of the green bars I should understand the lower line.
As seen the top line touches green bars 3 times
As seen the bottom line touches green bars 7 times

Thank you!

chartpoints.png
 
Last edited:
Top