Since this is basically an update to a previous solution I posted for you I changed the title of your question to reflect that we have added the ability to short by the bar count values.
In the solution below you will see that you nearly had this worked out. The original was using positive integers to increment that bearish bar counts. This one tiny detail prevented everything else from working. I included your original line of code along with my comments before replacing that line with the correction.
I also updated the color for the first bearish bar count from Cyan top Magenta. I just figured that would make the most sense given the rest of the color assignments. And the final color of your AssignBackgroundColor() should always be "Color.CURRENT". This will ensure your solution does not change the background color if none of the other conditions are true.
Here it is, all patched up and ready to go:
input trailType = {default modified, unmodified};
input atrPeriod = 9;
input atrFactor = 2.9;
input firstTrade = {default long, short};
input averageType = AverageType.exPONENTIAL;
def thisATR = ATRTrailingStop(trailType, atrPeriod, atrFactor, firstTrade, averageType).TrailingStop;
rec countBullish = if close < thisATR then 0 else countBullish[1] + 1;
# your original version is using positive integers for bearish bar count
# rec countBearish = if close > thisATR then 0 else countBearish[1] + 1;
# you must correct that by using negative integers for berarish bar count, as follows....
rec countBearish = if close > thisATR then 0 else countBearish[1] - 1;
plot data = if countBullish > 0 then countBullish else if countBearish < 0 then countBearish else 0; data.SetDefaultColor(Color.BLACK);
# I updated the color for first bearish candle to Megenta. The original was set to Cyan
AssignBackgroundColor(if countBullish == 1 then Color.CYAN else if countBullish > 1 then Color.GREEN else if countBearish == -1 then Color.MAGENTA else if countBearish < -1 then Color.RED else Color.CURRENT);