I indeed forgot the Delay in the code:

int Delay = 3;

The variable "crossed" is set to 3 or -3, then counted down or up until it's 0. This has the purpose that the signal stays valid until 3 bars after the crossover.

The "static" keyword is important here, as it keeps the content of the "crossed" variable when the function is left. Otherwise, crossed could not be used as a counter because it would be set to 0 every time the run() function is called.

This is a programming trick that was not mentioned in the course. It's however described in the "Variables" chapter of the manual.