Line with angles - Best Fit by points


Is there any way to automatically generate a straight polyline that fits the top points (in blue)?
It is quite straight forward when the line is straight in just one direction but not sure if possible when it presents some angles. (goal in the bottom image).

Many thanks