Use polyfit function:

https://www.zorro-trader.com/manual/en/polyfit.htm

An example of how to use it here (objective function in the last post):

https://opserver.de/ubb7/ubbthreads.php?...true#Post469722

Hope it helps.