Here’s a real simple script that will plot the moving average of your choice with the color of the line based on the slope of the line. If you want different colors, just change the two color constants in the line of code:
ave.AssignValueColor(if ave > ave[1] then color.cyan else color.dark_red);

# TS_MOVINGAVERAGE
# http://www.thinkscripter.com
# thinkscripter@gmail.com
# Last Update 15 MAR 2009
input displace = 0;
input length = 9;
input price = close;
input movingAverageType = {default Simple, Exponential, Weighted, Hull, Variable};
rec data;
switch (movingAverageType) {
case Simple:
data = compoundValue(1, Average(price[-displace], length), price);
case Exponential:
data = compoundValue(1, ExpAverage(price[-displace], length), price);
case Weighted:
data = compoundValue(1, wma(price[-displace], length), price);
Case Hull:
data = compoundValue(1, hullMovingAvg(price[-displace], length), price);
case variable:
data = VariableMA(price=price, length=length);
}
plot ave = data;
ave.SetLineWeight(2);
ave.AssignValueColor(if ave > ave[1] then color.cyan else color.dark_red);
ave.HideBubble();
#---------------- End Of Code ----------------