You can calculate the desired area with sma20 value + your desired percentage:
colorAreaPercentage = input(1 , "Colored area precentage" , input.integer , minval = 0)
sma20 = sma(close, 20)
barColor = close > sma20 and close < sma20 + (sma20 * colorAreaPercentage /100) ? color.fuchsia : close < sma20 and close > sma20 - (sma20 * colorAreaPercentage / 100) ? color.orange : na
if ((high >= sma20 and low <= sma20) or high == sma20 or low == sma20)
barColor := na
barcolor(barColor)
This will color 1% above the moving average and 1% below the moving average
Edit:
if ((high >= sma20 and low <= sma20) or high == sma20 or low == sma20)
barColor := na
This part of code will leave the touching candles uncolored.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…