CM_Ultimate_MA_MTF_V2 - Added Tilson T3

Defaults to Current Timeframe on Chart.
Ability to Plot 2nd Moving Average.
Ability to set Moving Averages to Custom Chart TimeFrame. Example Daily Ma on 60 Minute chart. Many Different Options from Weekly to 1 Minute.
Ability to Plot Cross where Moving Averages Cross (If using 2nd Moving Average).
Ability to Plot Highlight Bars when Price Crosses 1st Moving Average, or 2nd MA.

Moving Averages Supported in Inputs Tab
SMA - Simple Moving Average
EMA - Exponential Moving Average
WMA - Weighted Moving Average
HullMA - Hull Moving Average
VWMA - Volume Weighted Moving Average
RMA - Moving Average used in RSI - Similar to EMA
TEMA - Triple Exponential Moving Average
Tilson T3 - Tilson T3 Moving Average
Remove from Favorite Scripts Add to Favorite Scripts
//Created by user ChrisMoody 4-24-2014...Updated 7/28/2014 added Tilson T3
//Modified on 5-5-14 for 4apprentice08 with Optional BarColor based on Price  Crossing MA #1, or #2
//Modified on 7-25-2014 to Add in Tilson T3
//Plots The Majority of Moving Averages
//Defaults to Current Chart Time Frame --- But Can Be Changed to Higher Or Lower Time Frames
//2nd MA Capability with Show Crosses Feature
study(title="CM_Ultimate_MA_MTF_V2", shorttitle="CM_Ultimate_MA_MTF_V2", overlay=true)
src = close
useCurrentRes = input(true, title="Use Current Chart Resolution?")
resCustom = input(title="Use Different Timeframe? Uncheck Box Above", type=resolution, defval="D")
len = input(20, title="Moving Average Length - LookBack Period")
//periodT3 = input(defval=7, title="Tilson T3 Period", minval=1) 
factorT3 = input(defval=7, title="Tilson T3 Factor - *.10 - so 7 = .7 etc.", minval=0) 
atype = input(1,minval=1,maxval=8,title="1=SMA, 2=EMA, 3=WMA, 4=HullMA, 5=VWMA, 6=RMA, 7=TEMA, 8=Tilson T3")
spc=input(false, title="Show Price Crossing 1st Mov Avg - Highlight Bar?")
cc = input(true,title="Change Color Based On Direction?")
smoothe = input(2, minval=1, maxval=10, title="Color Smoothing - Setting 1 = No Smoothing")
doma2 = input(false, title="Optional 2nd Moving Average")
spc2=input(false, title="Show Price Crossing 2nd Mov Avg?")
len2 = input(50, title="Moving Average Length - Optional 2nd MA")
sfactorT3 = input(defval=7, title="Tilson T3 Factor - *.10 - so 7 = .7 etc.", minval=0)
atype2 = input(1,minval=1,maxval=8,title="1=SMA, 2=EMA, 3=WMA, 4=HullMA, 5=VWMA, 6=RMA, 7=TEMA, 8=Tilson T3")
cc2 = input(true,title="Change Color Based On Direction 2nd MA?")
warn = input(false, title="***You Can Turn On The Show Dots Parameter Below Without Plotting 2nd MA to See Crosses***")
warn2 = input(false, title="***If Using Cross Feature W/O Plotting 2ndMA - Make Sure 2ndMA Parameters are Set Correctly***")
sd = input(false, title="Show Dots on Cross of Both MA's")

res = useCurrentRes ? period : resCustom
//hull ma definition
hullma = wma(2*wma(src, len/2)-wma(src, len), round(sqrt(len)))
//TEMA definition
ema1 = ema(src, len)
ema2 = ema(ema1, len)
ema3 = ema(ema2, len)
tema = 3 * (ema1 - ema2) + ema3

//Tilson T3
factor = factorT3 *.10
gd(src, len, factor) => ema(src, len) * (1 + factor) - ema(ema(src, len), len) * factor 
t3(src, len, factor) => gd(gd(gd(src, len, factor), len, factor), len, factor) 
tilT3 = t3(src, len, factor) 

avg = atype == 1 ? sma(src,len) : atype == 2 ? ema(src,len) : atype == 3 ? wma(src,len) : atype == 4 ? hullma : atype == 5 ? vwma(src, len) : atype == 6 ? rma(src,len) : atype == 7 ? 3 * (ema1 - ema2) + ema3 : tilT3
//2nd Ma - hull ma definition
hullma2 = wma(2*wma(src, len2/2)-wma(src, len2), round(sqrt(len2)))
//2nd MA TEMA definition
sema1 = ema(src, len2)
sema2 = ema(sema1, len2)
sema3 = ema(sema2, len2)
stema = 3 * (sema1 - sema2) + sema3

//2nd MA Tilson T3
sfactor = sfactorT3 *.10
sgd(src, len2, sfactor) => ema(src, len2) * (1 + sfactor) - ema(ema(src, len2), len2) * sfactor 
st3(src, len2, sfactor) => sgd(sgd(gd(src, len2, sfactor), len2, sfactor), len2, sfactor) 
stilT3 = st3(src, len2, sfactor) 

avg2 = atype2 == 1 ? sma(src,len2) : atype2 == 2 ? ema(src,len2) : atype2 == 3 ? wma(src,len2) : atype2 == 4 ? hullma2 : atype2 == 5 ? vwma(src, len2) : atype2 == 6 ? rma(src,len2) : atype2 == 7 ? 3 * (ema1 - ema2) + ema3 : stilT3

out = avg 
out_two = avg2

out1 = security(tickerid, res, out)
out2 = security(tickerid, res, out_two)

//Formula for Price Crossing Moving Average #1
cr_up = open < out1 and close > out1
cr_Down = open > out1 and close < out1
//Formula for Price Crossing Moving Average #2
cr_up2 = open < out2 and close > out2
cr_Down2 = open > out2 and close < out2
//barcolor Criteria for Price Crossing Moving Average #1
iscrossUp() => cr_up
iscrossDown() => cr_Down
//barcolor Criteria for Price Crossing Moving Average #2
iscrossUp2() => cr_up2
iscrossDown2() => cr_Down2

ma_up = out1 >= out1[smoothe]
ma_down = out1 < out1[smoothe]

col = cc ? ma_up ? lime : ma_down ? red : aqua : aqua
col2 = cc2 ? ma_up ? lime : ma_down ? red : aqua : white

circleYPosition = out2

plot(out1, title="Multi-Timeframe Moving Avg", style=line, linewidth=4, color = col)
plot(doma2 and out2 ? out2 : na, title="2nd Multi-TimeFrame Moving Average", style=circles, linewidth=4, color=col2)
plot(sd and cross(out1, out2) ? circleYPosition : na,style=cross, linewidth=15, color=aqua)
//barcolor Plot for Price Crossing Moving Average #1
barcolor(spc and iscrossUp() ? (iscrossUp() ? yellow : na) : na)
barcolor(spc and iscrossDown() ? (iscrossDown() ? yellow : na) : na)
//barcolor Plot for Price Crossing Moving Average #2
barcolor(spc2 and iscrossUp2() ? (iscrossUp2() ? yellow : na) : na)
barcolor(spc2 and iscrossDown2() ? (iscrossDown2() ? yellow : na) : na)
Nice! Thanks Chris.
No Problem
Chris, this is exactly what I was looking for...T3-Tilson plays a real part of all my trading analysis...again thanks for updating this it's a great help!
Good...Glad you like it...
hi Chris,

Does this indicator repaint?
+1 Reply
Yes and No...It never repaints the past...obviously it can repaint on current bar depending if the current bar moves enough to change the MA direction.

The other variable is in the Inputs Tab. It's set to Smooth the Color change for X number of bars. The default is two bars back it never repaints. If you set value to 1 then only the current bar can repaint based on the first sentence above. But if you set the Smoothing period to 10...then it could repaint line back to 10 bars...but wouldn't repaint values from 11 bars back.

If you don't want it to repaint at all set the smoothing to 1...then only the current bar can cause it to repaint. but it will never repaint the color for the last closed bar.
opltrader ChrisMoody
Awesome, thank you so much! Would you be able to advise if you code for MT4?
nsalvato PRO opltrader
@opltrader, I would like this as well!
Hey Chris Thanks for this,

What should I do to get an alert, when the trend is up and a bar opens below the trend line with a predetermined offset? I believe I have to customize the source code, I'new to trading and do have bit of background in coding.

Any help would be appreciated.


ChrisMoody PRO chathura.ambegoda
Never saw your comment...if you still need help let me know.
Yes Pls. If you have a moment to spare. Thanks.
What a great indicator / study. Quick question; have you ever thought about adding a 3rd color for when the slope of the line is essentially flat? The color code is currently binary.
But the thought occurred to me, if the slope is within some number of degrees (plus or minus) of 0, a 3rd color would show (yellow?)
How to install your script? :) please
First of all, tanks for your work.

It's strange when I put two of that indicator at the same time. The lines are moving in a strange way when I zoom or move the chart. for example the 200ema can be above or under the bars. The stranger thing is that this bug appear only when I save my two indicators as a study template and I add it to another chart.

In short, when I put those two indicator, it works. When I need them as a study template, it dies these strange things. Do you have an explication?

I'm looking to put 4 différent EMA lines (15, 30, 50 and 200) and I need them to change color when they go up or down. Do you have something that can make that?

Thanks again,

HullMA - Hull Moving Average is really help me a lot. Love it, and Thanks for all your hard work.
ChrisMoody PRO chenchen3529
@chenchen3529, Thank You for the comment.
Being a newbe this is really great. Im using the cross's to great effect its like seeing into the future.
I then use
CM ultimate MA MTF V2 as a confirmation.
Thank you so much.
This is amazing! Thanks!
Greate indicator!
Do you know how to setup an alert with this indicator?
I need to create the alert when 2 "Ultimate_MA" are green or red.

+1 Reply
hi chris,
How do i add a strategy back-test on this indicator? I am not sure which symbol is representing the overall red line and green line.


Your Question - How do i add a strategy back-test on this indicator?

Answer - To add a strategy that references any type of condition involving this indicator...You need to know how to code Strategies...and/or ask for someones help in the PineScript Room. You just need to be very specific as to what rules get you in to a trade...and what rules get you out of a trade....etc.

I do design trading systems for a living for me personally, Unfortunately I just can't take on any personal projects for individuals right now. I love helping other traders...due to the amount of requests I receive the only way I can help everyone is to host free webinars where anyone who wants to can attend. Unfortunately, the last time I offered to do a free webinar in a post...the post was taken down within the hour...something regarding it being viewed as me marketing to the community. I understand TradingView has to take a stance to protect the community from people joining just to market there products or services...I wish I could do free educational sessions for anyone who is interested in learning several different topics/free courses I'd like to offer...but at least for right now I'm not aloud to do so...

Your comment - not sure which symbol is representing the overall red line and green line.

Answer - Any indicator references the actual symbol you place on the chart...Unless the creator hard codes it in to reference a specific symbol. That wasn't done heat...the MA was designed to be used just like any other moving average you would use...I just added in the capability to reference a different time frame vs. the time frame on the actual chart...and I added in the ability to...
1 - have the color change based on trend of a look back period you choose.
2 - Plot a 2nd Moving Average on the chart, and if so reference the cross of the 2 MA's.
3 - Created the ability to switch the MA to a Simple Moving Avg., Exponential MA, Weighted MA, Hull MA, or Volume Weighted MA.

Plus a few other items...but you get the point...and all you have to do is reference the Inputs Section.
Hello To Everyone....Quick Question.

I've been gone for a while working on a few projects. The question was asked above by @yurius regarding Alerts. I just looked and I had created V3 of this indicator with Alert capability a LONG time ago and I guess I never posted it. Currently (as we use to ) do I punish a new indicator, or can we edit/update existing indicators and strategies now?

Any instructions would greatly help...I have updates on a ton of items I posted that I can publish for everyone.
yurius PRO ChrisMoody
@ChrisMoody, I think it's better to update existing indicators.
ityounus PRO ChrisMoody
dear @ChrisMoody, any alert update
+1 Reply
@ChrisMoody, could you send it to V3? Thank you!
special thanks
Hi Chris,
Great script! The color change is fantastic!
Would it be difficult to add an offset to the 1st MA? The idea would be to use two CM_Ultimate_MA_MTF_V2 and combine the color change signal with the ribbon cross signal shown in the chart below.

If it's of interest to anyone, I managed to do it. I can't code so it's very raw and you can only change the offset value in the script on the last line: offset=x:

study(title="Colored SMA Offset", shorttitle="Colored SMA Offset", overlay=true)

smaplot = input (true, title="Show SMA on chart")
len = input(6, minval=1, title="sma Length")
src = input(close, title="Source")
offset = input(0, title="Offset")
out = sma(src, len)
up = out > out
down = out < out
mycolor = up ? green : down ? red : blue
plot(out and smaplot ? out :na , title="SMA", color=mycolor, linewidth=1, offset=1)

hey chris.. how i can apply this on my charts? please. thank you
Is this script still valid? Have people had success with this?
Hola Chis como puedo descargar el indicador. vale para cualquier plataforma?.Gracias
Thank you ! can you explain how use it?
United States
United Kingdom
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