After many different tests, I have noticed something.
In my script, I have some calculations (the spread or ZScore of the 2 series) that must be made only after the LookBack period has elapsed. If I try to calculate this ZScore before LookBack has elapsed, I would find "0" and results would lead to errors.
In order to calculate this ZScore after LookBack, I did this:
if (Bar > StartBar) {
var criticalValue = -1;
//Some calculations...
}
And I really think that this is the reason why my optimization only works in the first step of the WFO.
For now, I will comment out the "NumWFOCycles", and I will use normal Training (Vertical Split optimization, as it is called in the manual).
Any ideas how I could make WFO and not fall into the error of doing these calculations before the LookBack has passed?