Moving Average Custom indicator help

 
I got an moving Average indicator that gives arrow signals for buy and sell when two moving Average cross, I now want to filter the signals so it can give give only sell signals in downtrend and buy signals in Uptrend. I don't mind sharing my full code here. I'm a beginner in coding
Reason: