ChrisMoody

Code For SMA and EMA That Change Color Based On Slope!

FX:AUDUSD   Australian Dollar/U.S. Dollar
5230 34 40
I Like Moving Averages That Change Colors Based On Their Direction. Gives Visual Effect If I Should Buy Support Or Sell Resistance.

Both The EMA and SMA are Smoothed to 2 Periods. Directions are in Code If You Want To Change.

Directions Are On Chart In White Box To Get Codes.
Dear ChrisMoody, Life changing for my work! Thank you so much. Sincerely, Beauty
Reply
ChrisMoody PRO BitcoinMedusa
Thanks for the comment...I like your chart on Pivots...For about 2 years I traded Only using Pivots and One other Indicator. I'll post on your thread a few insights I found.
+1 Reply
Just found you on Trading charts. Your idea's of changing color s. according to directtion are fantastic. I already have incorporated into my charts. what a difference! More later. Need to get back to my trading. Thank You Mithril
Reply
Thanks...If you take a look I've posted several others and I have a Lot coming....
Reply
How would I write a code for slope differential with all my indicators and the actual chart price?


I could see this as very useful for chartist that are hunting for divergences within the indicators and current price?

An even more advanced code could take two previous bottoms or tops, and calculate differences in slope compared to slope in whichever indicator chosen by the user (RSI, Fisher, CCI).
Reply
ChrisMoody PRO QuantitativeExhaustion
JR....We speak the same language...Divergences have been my favorite setup for since the day I started trading. We should talk b/c I've got about 15 years of insights I've found with Divergences and I'm sure you do to.

I'm talking to the Tech guys regarding the capabilities right now. If it can be coded now I'm on it.....If not as soon as It's a possibility...Remind me in a week or so if you don't hear back....
Reply
ChrisMoody PRO QuantitativeExhaustion
JR....Great News...Tech support had already planned to create a divergence indicator to possibly roll out as soon as this week...It will default to a indicator like the RSI but will allow us to change the indicator to others beside the RSI....
Reply
Chris.....thank you for this chart template !!!
Reply
Appreciate the comment...
Reply
Thank you very much for these scripts.
Unfortunately only one of the scripts can be saved to the Custome Scripts. Do you have any idea what might be the reason?
Reply
motleifaul motleifaul
Forget it. I don't know what the reason was. But now it works.
Reply
ChrisMoody PRO motleifaul
Great...I'm learning as I go along...take a look at pezq's comment below
Reply
Chris, thanks for your very useful work. I have found the best way to get the indicators into my charts is as follows.
Open the chart in "make it mine"
Click on the curly brackets on your indicator to reveal the code
select all
copy
open a new blank chart in a new tab
open the script editor
select new
delete the 8 lines of starter code
paste (your code)
save
The indicator will now have saved in your scripts directory with the correct name

I couldnt make the other instructions work properly. However this method works 100%


Reply
Thanks....I just copied your instructions....Greatly appreciate it.
Reply
Thanks Chris for your nice and powerfull systems.Keep going on
Reply
I'd like to get this code because I'm trying to learn how to do this with MultiCharts, without success. But I don't see a white arrow at the top right or left or anywhere... I'm fairly new to learning how to use TradingView, so how DO I get to the code?
Reply
Hello,

It's a pleasure to find another MultiCharts user. This code is outdated. Here is the most current version
CM_Ultimate_MA_MTF_V2

Let me know if you need any help...
Reply
denovo ChrisMoody
Well, you know,uh... hmmm. I really know next-to-diddly about coding ANYTHING. The new code looks impressive, but you wouldn't happen to still have the outdated code, would you? I'm just trying to figure out how to get a SMA plot color to change at the same time the slope changes, but so far I can only get the plot color to change one bar AFTER the slope changes direction... isn't there some simple function or something to get it to change at the same time?

Thanks...
Reply
I deleted that code...it's outdated....color change is easy....just make sure you have a >= for one of your colors. Right before the plot statements use a code like this:

//This says if your ema plot (or any moving average) is greater or equal to the previous bar then the color is lime, if the ema is less than ema of the previous bar then the color is red. Most people make a mistake of not coding in 100% of the outcomes. There are 3 possibilities. 1. ema can be greater than the ema of the previous bar...2. it can be less than... 3. Or it can be equal. the code below handles all 3 possibilities.

col = ema1 >= ema1 ? lime : red

plot(ema1, title="EMA Color based on Trend", style=linebr, linewidth=4, color=col)

If your using a moving average that is very sensitive to price you can also smooth out the color changes by saying
//col = ema >= ema ? lime : red...or you can also try , or …


also I typically leave the option up to the individual. so in the inputs section I may say

lb = input(1, minval=1, maxval=10, title="Smoothing period of Color Change. 1= No smoothing, 2 or higher Smooths the color change")

Then the code would be:

col = ema1 >= ema1 ? lime : red

plot(ema1, title="EMA Color based on Trend", style=linebr, linewidth=4, color=col)
Reply
ChrisMoody PRO ChrisMoody
I found the old codes...very basic.

// Created By User ChrisMoody
// This Indicator Plots a EMA with Color Based On Upward or Downward Slope
// Created 1-16-2014

study(title = "CM-EMA-DirectionColor", shorttitle="CM-EMA-DirectionColor", overlay=true)

src = close, len = input(20, minval=1, title="EMA Length")

ema1 = ema(src, len)

//ema is smoothed to 2 periods, you can change smoothing by adjusting the number in the bracket below
//example would react quicker and would increase smoothing
plot_color = ema1 >= ema1 ? lime : ema1 < ema1 ? red : white


plot(ema1, title="EMA Plot", style=line, linewidth=4, color = plot_color)
Reply
ChrisMoody PRO ChrisMoody
// Created By User ChrisMoody
// This Indicator Plots a SMA with Color Based On Upward or Downward Slope
// Created 1-16-2014

study(title = "CM-SMA-DirectionColor", shorttitle="CM-SMA-DirectionColor", overlay=true)

src = close, len = input(200, minval=1, title="EMA Length")

sma1 = sma(src, len)

//ema is smoothed to 2 periods, you can change smoothing by adjusting the number in the bracket below
//example would react quicker and would increase smoothing
plot_color = sma1 >= sma1 ? lime : sma1 < sma1 ? red : white


plot(sma1, title="SMA Plot", style=line, linewidth=4, color = plot_color)
Reply
ChrisMoody PRO ChrisMoody
I made a mistake...the color statement would be would be

col = ema1 >= ema1 ? lime : red
Reply
ChrisMoody PRO ChrisMoody
It's taking the brackets out for some reason...the second ema1 would have a bracket with lb in the brackets.

it took the brackets out of ALL the code examples I posted...I'll give you a link below to get the code
Reply
Here is the indicator above the way I would code it now...you can copy and paste the code from the link:

http://pastebin.com/jQsNB1hN
Reply
denovo ChrisMoody
I haven't checked the link yet, but thank you, thank you, thank you! Just from what I see above, it's getting easier to understand. Does the same syntax/code work for Power Language?
Reply
denovo denovo
Ah, of course not - dumb question.
Reply
Thanks ChrisMoody, I tried switching btw plain 20EMA and your color changing indicator, what a difference. I do wish there's an alert on price crossing the indicator. I tried the "Crossing up" in the alert box but would not work. Tks in advance.

Reply
There is a much more updated version of this. CM_Ultimate_MA_MTF_V2

However On Monday I will release CM_Ultimate_MA_MTF_V3 .... and V3 Will have blatantly obvious Alerts in it.
Reply
Hi Chris - wondering if you can add a 3rd color (yellow) for when the slope is +/- 3 degrees from 0* (basically sideways)?
Reply
ChrisMoody PRO MarketsCJR
Wow this is an old post...I have many Moving average indicators with more features...but I'm not sure how to code slope...I'll have to look in to it
Reply
I would like to get this script...can't seem to do download process...can you help
Reply
@stiffstyx,

Here is a version with MANY additional capabilities

CM_Ultimate_MA_MTF_V2

Reply
thank you
Reply
So disappointed when I discovered that EMA_Slope_Color would not work with NinjaTrader 8 . NinjaTrader tells me won't be able to use it again until someone updates the indicator to work with NT8. Can anyone give me any hope that this will happen shortly? Mel Hardman mel@melhardman.com
+1 Reply
Ideas Scripts Chart
United States
United Kingdom
India
España
France
Italia
Polska
Brasil
Россия
Türkiye
日本
한국
Home Stock Screener Forex Signal Finder Economic Calendar How It Works Chart Features House Rules Moderators For the WEB Widgets Stock Charting Library Priority Support Feature Request Blog & News FAQ Help & Wiki Twitter
Private Messages Chat Ideas Published Followers Following Priority Support Public Profile Profile Settings Account and Billing Sign Out