You need to supply more information, we can't help you unless you help us first. I'm guessing by your code that you need a guard? If so, then I can give you some simple pseudocode:
If link is within a certain radius:
move towards link
if I'm moving towards link and he gets too far away:
stop moving towards link
if I'm not moving towards link, but I'm also not moving:
pick a random direction, move in that direction
it's pretty basic stuff. If you want, you can add a delay in there before it moves, and make it look around, etc. That's all the help I can offer now wiht what info you've given though.