As jstap says, it is not an easy thing to do. Can you please specify how long in the past those 'previous higher' fractals are supposed to be searched for? Because the longer the distance in the past, the more complicated and less efficient to be optimized.
F