The wave code you posted is interesting if you watch it live. I amended it to make it a ShowMe study so I could see retrospectively when it switched from one wave to another and found that there is quite a delay at times ie it doesn't signal the change from one wave to another until you are well into the next wave. But nevertheless very useful if you are into wave analysis.
Your observation is correct and there is a delay for the the next phase to appear., saying that one can still use this code to give him an idea what the next run would be ..