Buy based on Buy signal x buys ago

"Hello everyone,
Can anyone please advice me how to code a buy signal based that is dependant upon a previous buy signal being a lower Close than the Current Close
Example:
Buy = CurrentBuySignal > PrevBuySignal

Thanks Keith "

Lookup the valuewhen() function.