That's called "Walk forward optimization".