How to draw a line that defines a "move" or swing


I want to automatically draw lines that best describe price moves. Please look at the chart. The lines make no predictions, they are drawn after the completion of the move.

I am searching the library, I can't find anything.

Ideally I would like the script to decide where to start and stop each line. But It would be good enough if I provided the pivot or turn points and then the script gave me an approximation of the line.

I am thinking of the line corresponding to the standard deviation of prices.

I think this is a clasical problem, so I am sure somebody else thought of it and solved it before me.trend-lines

It seems that Liner Regression is a good approximation for this trendline.