@STONEIPA That first declaration line is not valid in Thinkscript, only in Pinescript... Delete it and you should be good to go... Also, Thinkscript doesn't have a ExpMovingAvg(), it has ExpAverage(price, length)... The following code works...
Ruby:
input length1 = 3;
input length2 = 8;
def ema1 = ExpAverage(close, length1);
def ema2 = ExpAverage(close, length2);
def above = ema1 > ema2;
def below = ema1 < ema2;
def aboveCount = CompoundValue(1, if above then aboveCount[1] + 1 else 0, 0);
def belowCount = CompoundValue(1, if below then belowCount[1] + 1 else 0, 0);
plot count = if above then aboveCount else if below then belowCount else 0;
AssignBackgroundColor(if above then Color.GREEN else if below then Color.RED else Color.GRAY);