Add an input for color changes, crossing and scan

hi to all this great group. @barbaros need your help with this thinkscript, i just want to add a color candles input, i will like to paint the candles green when is a bullish cross and red when is a bearish cross, also if is possible to add an scan will be great. thanks in advance.
here is the code:

declare lower;

input length = 50;
input averageType = AverageType. SIMPLE;

def avg = MovingAverage(averageType, close, length);

plot percent = ((close - avg) / close) * 100;

input lengthavg = 20;
plot percentavg = MovingAverage(averageType,percent,lengthavg);

AddCloud(if percentavg < percent then percentavg else Double.NaN, percent, Color.GREEN, Color.GREEN);
AddCloud(if percentavg > percent then percentavg else Double.NaN, percent, Color.RED, Color.RED);

plot zeroline = 0;
zeroline.setDefaultColor(color.white);

plot overbought = absValue(stdevAll(percent));
overbought.setDefaultColor(color.red);

plot oversold = -absValue(stdevAll(percent));
oversold.setDefaultColor(color.red);
 
Top