ChrisMoody

Example of Code for Moving Average Cross - Changing Colors

Famous 7 Time World Trading Champion Chuck Hughes found the 50 and 100 EMA to be the best Signal for a Change in Trend. Through extensive back-testing he found these EMA’s to give the earliest signal that also resulted in a Long-Term Change in Trend.

Dotted Line represents Long-Term EMA. The 100 EMA in this example.
Solid line represents the Short-Term EMA. The 50 EMA in this example.

If Short-Term EMA is ABOVE Long-Term EMA...Color = Green.
If Short-Term EMA is BELOW Long-Term EMA...Color = Red.

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?
//Created by user ChrisMoody
//Long EMA = Dots, Short EMA = Line
//If Short EMA is ABOVE Long EMA = Lime Color, If Short EMA is BELOW Long EMA = Red Color
study(title="_CM_Double EMA Trend Color", shorttitle="_CM-2EMA-Trend", overlay=true)
src = close, len = input(50, minval=1, title="Short EMA")
src2 = close, len2 = input(100, minval=1, title="Long EMA")
emaShort = ema(src, len)
emaLong = ema(src2, len2)

spanColor = emaShort>=emaLong ? lime : red

p1 = plot(emaShort, title="EMA Short", style=line, linewidth=4, color=spanColor)
p2 = plot(emaLong, title="EMA Long", style=circles, linewidth=3, color=spanColor)

fill(p1, p2, color=silver, transp=40, title="Fill")

//If you do not want the Fill gradient between the EMA's follow the steps below.

//Erase the p1 = in line 12 and 13 so plot is at the far left
//Erase line 15 or put two forward slashes infront of the word fill, just like the two forward slashes at the beginning of this line.