I have strategy. But can't test it by hands. It takes ages.

 

The problem is I can't get the previous wave highest and lowest values. and also can get current wave values.

Reason: