I have noticed that this crash is due to not enough bars to 'learn' to use in the optimization. Is that possible? The script works with 1day bars (barperiod 1440), and if I tune lookback and try different -smaller- timeframes, this error stops emerging.

But, what can I do to make this script working in barperiod 1440 and make optimizations? How can I know how many lookback bars the script needs for calculations?

Thanks to everyone reading this.