In order to complete this within the allotted time I borrowed the code from the built-in StochasticFull included with Thinkorswim. I made a few minor changes and added new lines for the bar count and display functionality.
This may not perfectly fit what you requested. But this is what I am able to provide free of charge:
input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 10;
input priceH = high;
input priceL = low;
input priceC = close;
input slowing_period = 3;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = { "No", default "On FullK", "On FullD", "On FullK & FullD"};
def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC - lowest_k;
def c2 = Highest(priceH, KPeriod) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;
def FullK = MovingAverage(averageType, FastK, slowing_period);
def FullD = MovingAverage(averageType, FullK, DPeriod);
def upK = FullK crosses above over_sold;
def upD = FullD crosses above over_sold;
def downK = FullK crosses below over_bought;
def downD = FullD crosses below over_bought;
def UpSignal;
def DownSignal;
switch (showBreakoutSignals) {
case "No":
UpSignal = no;
DownSignal = no;
case "On FullK":
UpSignal = if upK then over_sold else no;
DownSignal = if downK then over_bought else no;
case "On FullD":
UpSignal = if upD then over_sold else no;
DownSignal = if downD then over_bought else no;
case "On FullK & FullD":
UpSignal = if upK or upD then over_sold else no;
DownSignal = if downK or downD then over_bought else no;
}
#---------- Display Section
rec countBullish = if FullK < FullD then 0 else if UpSignal then 1 else if countBullish[1] <> 0 and FullK > FullD and FullK > over_sold then countBullish[1] + 1 else 0;
rec countBearish = if FullK > FullD then 0 else if DownSignal then 1 else if countBearish[1] <> 0 and FullK < FullD and FullK < over_bought then countBearish[1] + 1 else 0;
plot currentCount = Max(countBullish, countBearish);
currentCount.AssignValueColor(if currentCount <> 0 then Color.BLACK else Color.CURRENT);
AssignBackGroundColor(if countBullish > 0 then Color.GREEN else if countBearish > 0 then Color.RED else Color.CURRENT);