ChrisMoody

Ultimate Moving Average-Multi-TimeFrame-7 MA Types

All Moving Averages and Features Built In To ONE Indicator. The Only Moving Average Indicator You Will Need. Details In 1st Post.
Remove from Favorite Scripts Add to Favorite Scripts
//Created by user ChrisMoody 4-24-2014
//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", shorttitle="CM_Ultimate_MA_MTF", overlay=true)
//inputs
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")
atype = input(1,minval=1,maxval=7,title="1=SMA, 2=EMA, 3=WMA, 4=HullMA, 5=VWMA, 6=RMA, 7=TEMA")
cc = input(true,title="Change Color Based On Direction?")
smoothe = input(2, minval=1, maxval=10, title="Color Smoothing - 1 = No Smoothing")
doma2 = input(false, title="Optional 2nd Moving Average")
len2 = input(50, title="Moving Average Length - Optional 2nd MA")
atype2 = input(1,minval=1,maxval=7,title="1=SMA, 2=EMA, 3=WMA, 4=HullMA, 5=VWMA, 6=RMA, 7=TEMA")
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

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) : tema
//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

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) : tema

out = avg 
out_two = avg2

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

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 : aqua

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=5, color=yellow)

How to set an alert on this study please ?

Need to set alert "buy" on green and alert "sell" on red color of the signal, thank you in advance.
+24 Reply
@Romalian, Any luck with this? I am keen for the same thing
+1 Reply
Thanks for your excellent work, now it is very convenient switching between weekly and daily charts.
BTW, How is it possible to add the 3rd multi time frame line in this script? thank you.
+6 Reply
I tried turning this into a strategy to start some backtesting. renamed it to "strategy" instead of "study" and added the following simple buy/sell rules:
strategy.entry("long", true, 1, when = ma_up)
strategy.exit("exit", "long", when = ma_down)

However, when I backtest the strategy enters at the beginning of the backtest and leaves that trade open until the end. From the signals in the chart I see there should have been many trades happening, so there must be something wrong with my script. Can anyone help me? Im sorry if this is a stupid questions, I only started using pine last week and I have searched through the pine documentation but still couldnt see whats wrong in the script.

thanks
+10 Reply
@goupoboy, Did you have any luck? I would also like to backtest
Reply
goupoboy Crypto_Ben
@Crypto_Ben,
Didn't manage to succeed. Not sure exactly what's going on but could be the script suffers from hindsight bias/ repainting of chart. Hence different signals when you make a backtest. But not sure about that - have up working with this script
Reply
@goupoboy, OK cool. I'll keep looking at how to do this and will let you know if I find anything
Reply
This is awesome! I have hated having to select two indicators for the TEMA and VWMA. This solves this problem beautifully! Thank you for writting this. I look forward to checking out anything else you have posted.
Reply
Hi Chris,

You mention "Details In 1st Post.", can you please point where I can find this, scrolled this page but could not figure out.

Thanks for your help.

Regards,
Pramodh
+23 Reply
Hi:

Could I get the mq4 file?

I do not know how to code it
Reply
EN English
EN English (UK)
EN English (IN)
DE Deutsch
FR Français
ES Español
IT Italiano
PL Polski
SV Svenska
TR Türkçe
RU Русский
PT Português
ID Bahasa Indonesia
MS Bahasa Melayu
TH ภาษาไทย
VI Tiếng Việt
JA 日本語
KO 한국어
ZH 简体中文
ZH 繁體中文
AR العربية
Home Stock Screener Forex Signal Finder Cryptocurrency Signal Finder Economic Calendar How It Works Chart Features House Rules Moderators Website & Broker Solutions Widgets Stock Charting Library Feature Request Blog & News FAQ Help & Wiki Twitter
Profile Profile Settings Account and Billing My Support Tickets Contact Support Ideas Published Followers Following Private Messages Chat Sign Out