I want to generate buy signal at MACD crossover provided there is no reverse crossover in last 10 days. what is wrong with this code? It does not work.

I wish to avoid whipsaws due to frequent crossovers during trading range. I want to trade on clean crossover signals… It may reduce the number of trades. So I want to check if there has been a recent crossover of MACDsignal over MACD, in which case I want to skip the trade. 10 day period is chosen as random number which need to be changed.
I tried using REF function like
REF(MACD(12, 26, 7, EXPONENTIAL),1) < REF(MACDSignal(12, 26, 7, EXPONENTIAL),1)
and
REF(MACD(12, 26, 7, EXPONENTIAL),2) < REF(MACDSignal(12, 26, 7, EXPONENTIAL),2)
and
REF(MACD(12, 26, 7, EXPONENTIAL),3) < REF(MACDSignal(12, 26, 7, EXPONENTIAL),3)
and
REF(MACD(12, 26, 7, EXPONENTIAL),4) < REF(MACDSignal(12, 26, 7, EXPONENTIAL),4)
etc, But this code seems to hang & I need to restart Pi.
Ofcourse LASTIF is not mandatory if this condition can be implemented in any other way.