I'm glad you provided the link to the previous post so the rest of our viewers will be able to understand the context of that previous request. But more importantly because the code you provided is not complete. You left off the first six lines from the code in the previous solution and it will not work without those lines.
Here is the code you requested:
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
def value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def avg = MovingAverage(averageType, value, MACDLength);
def diff = Value - avg;
def colorGreen = diff >= 0 and diff > diff[1];
def colorDarkGreen = diff >= 0 and diff < diff[1];
def colorRed = diff < 0 and diff < diff[1];
def colorDarkRed = diff < 0 and diff > diff[1];
rec countGreen = if colorGreen and !colorGreen[1] then 1 else if colorGreen then countGreen[1] + 1 else 0;
rec countDarkGreen = if colorDarkGreen and !colorDarkGreen[1] then 1 else if colorDarkGreen then countDarkGreen[1] + 1 else 0;
rec countRed = if colorRed and !colorRed[1] then 1 else if colorRed then countRed[1] + 1 else 0;
rec countDarkRed = if colorDarkRed and !colorDarkRed[1] then 1 else if colorDarkRed then countDarkRed[1] + 1 else 0;
plot data = if colorGreen then countGreen else if colorDarkGreen then countDarkGreen else if colorRed then countRed else if colorDarkRed then countDarkRed else 0;
data.AssignValueColor(if data <> 0 then Color.BLACK else Color.CURRENT);
AssignBackgroundColor(if colorGreen then Color.GREEN else if colorDarkGreen then Color.DARK_GREEN else if colorRed then Color.Red else if colorDarkRed then Color.DARK_RED else Color.CURRENT);