ChrisMoody

MacD Custom Indicator-Multiple Time Frame+All Available Options!

This MacD Indicator has every feature available. See First Post for Details.
Remove from Favorite Scripts Add to Favorite Scripts
//Created by user ChrisMoody updated 4-10-2014
//Regular MACD Indicator with Histogram that plots 4 Colors Based on Direction Above and Below the Zero Line
//Update allows Check Box Options, Show MacD & Signal Line, Show Change In color of MacD Line based on cross of Signal Line.
//Show Dots at Cross of MacD and Signal Line, Histogram can show 4 colors or 1, Turn on and off Histogram.
//Special Thanks to that incredible person in Tech Support whoem I won't say you r name so you don't get bombarded with emails
//Note the feature Tech Support showed me on how to set the default timeframe of the indicator to the chart Timeframe, but also allow you to choose a different timeframe.
//By the way I fully disclose that I completely STOLE the Dots at the MAcd Cross from "TheLark"

study(title="CM_MacD_Ult_MTF", shorttitle="CM_Ult_MacD_MTF")
source = close
useCurrentRes = input(true, title="Use Current Chart Resolution?")
resCustom = input(title="Use Different Timeframe? Uncheck Box Above", type=resolution, defval="60")
smd = input(true, title="Show MacD & Signal Line? Also Turn Off Dots Below")
sd = input(true, title="Show Dots When MacD Crosses Signal Line?")
sh = input(true, title="Show Histogram?")
macd_colorChange = input(true,title="Change MacD Line Color-Signal Line Cross?")
hist_colorChange = input(true,title="MacD Histogram 4 Colors?")

res = useCurrentRes ? period : resCustom

fastLength = input(12, minval=1), slowLength=input(26,minval=1)
signalLength=input(9,minval=1)

fastMA = ema(source, fastLength)
slowMA = ema(source, slowLength)

macd = fastMA - slowMA
signal = sma(macd, signalLength)
hist = macd - signal

outMacD = security(tickerid, res, macd)
outSignal = security(tickerid, res, signal)
outHist = security(tickerid, res, hist)

histA_IsUp = outHist > outHist[1] and outHist > 0
histA_IsDown = outHist < outHist[1] and outHist > 0
histB_IsDown = outHist < outHist[1] and outHist <= 0
histB_IsUp = outHist > outHist[1] and outHist <= 0

//MacD Color Definitions
macd_IsAbove = outMacD >= outSignal
macd_IsBelow = outMacD < outSignal

plot_color = hist_colorChange ? histA_IsUp ? aqua : histA_IsDown ? blue : histB_IsDown ? red : histB_IsUp ? maroon :yellow :gray
macd_color = macd_colorChange ? macd_IsAbove ? lime : red : red
signal_color = macd_colorChange ? macd_IsAbove ? yellow : yellow : lime

circleYPosition = outSignal
 
plot(smd and outMacD ? outMacD : na, title="MACD", color=macd_color, linewidth=4)
plot(smd and outSignal ? outSignal : na, title="Signal Line", color=signal_color, style=line ,linewidth=2)
plot(sh and outHist ? outHist : na, title="Histogram", color=plot_color, style=histogram, linewidth=4)
plot(sd and cross(outMacD, outSignal) ? circleYPosition : na, title="Cross", style=circles, linewidth=4, color=macd_color)
hline(0, '0 Line', linestyle=solid, linewidth=2, color=white)
Features of this indicator: MacD w/ Ability to see Different Timeframes!

-Defaults automatically to chart timeframe.
-Ability to change to reflect a Higher or Lower Timeframe.
-CheckBox to have MacD line change colors when it crosses the Signal Line.
-CheckBox to take MacD and Signal line off, just leaving Histogram.
-Show Dots at MacD - Signal Line Cross.
-CheckBox to take Histogram off chart.
-Checkbox to change Histogram from 4 colors to 1 color (Gray is Default).

Video On Importing Custom Indicator from PasteBin Link Below:
http://blog.tradingview.com/?p=265

Link to Code for Indicator:
http://pastebin.com/P9Ru20mb
+3 Reply
pekipek
2 years ago
thanks dude!
Reply
Thank you. This would be useful for me.
Reply
ChrisMoody PRO AhilanThurairajah
2 years ago
Thanks guys...the custom script that allows indicator to default to chart timeframe while giving you the ability to apply indicator to a different timeframe is great. I'll be recoding all of my indicators...several will be coming out.
Reply
SamuelOssom ChrisMoody
2 years ago

Please add
a comment… Positive feedback and constructive criticism are important to authors and the community.
Reply
SamuelOssom SamuelOssom
2 years ago
Hey, chris
good job this is a very good and useful indicator.

I am very impressed with your work and hope to follow you and learn more from you as time goes on.

Reply
pekipek
2 years ago
yeah same here, I was trying to figure out how to do that and found a very inefficient way, however I could not find the efficient way you found 8-). Thanks again!
Reply
ChrisMoody PRO pekipek
2 years ago
Full disclosure...I hade it coded the wrong way...I asked tech support about another issue and they gave me that code also...I was asking them about using the Cross feature to place the dots. It was working if indicator was set to same timeframe as chart...but the dots weren't working if indicator was on diff timeframe. The code they gave for that I haven't seen before either....Great learning lesson
Reply
J.P.S.
2 years ago
Thanks CM, great help. I see in your custom indicators you have lots, where can I find those or those. Thanks again.
Reply
J.P.S. J.P.S.
2 years ago
Found yours, Thanks.
Reply
l330n PRO
2 years ago
Leeon, thank you Chris, for the indicators for the little guy's P.S where can I get more of your "AWESOME" scripts...
Reply
ChrisMoody PRO l330n
2 years ago
I have a bunch coming out over the next few weeks so easiest way is to follow me and you will get notified...

Go to : https://www.tradingview.com/u/ChrisMoody/#published-charts
To see my other posts...I will be recoding a lot of these...so if you like one go ahead and get it but leave a comment and when I update the indicator I will post it wither there or in a new chart...but I will provide ling at bottom of page so you will automatically get notified if there are any updates.
Reply
baldy
2 years ago
you are very A W E S O M E !! I've been trying to make code for this, it was epic fail lol. Thank you so much!! :)
Reply
ChrisMoody PRO baldy
2 years ago
Baldy...here is a tip for making the Default interval the current timeframe and being able to change time frames if desired:

study(title="CM_MacD_Ult_MTF", shorttitle="CM_Ult_MacD_MTF")
source = close
useCurrentRes = input(true, title="Use Current Chart Resolution?")
resCustom = input(title="Use Different Timeframe? Uncheck Box Above", type=resolution, defval="60")
smd = input(true, title="Show MacD & Signal Line? Also Turn Off Dots Below")
sd = input(true, title="Show Dots When MacD Crosses Signal Line?")
sh = input(true, title="Show Histogram?")
macd_colorChange = input(true,title="Change MacD Line Color-Signal Line Cross?")
hist_colorChange = input(true,title="MacD Histogram 4 Colors?")

res = useCurrentRes ? period : resCustom

fastLength = input(12, minval=1), slowLength=input(26,minval=1)
signalLength=input(9,minval=1)

***The first part of the code above has the 3 lines below that allow for this feature....
useCurrentRes = input(true, title="Use Current Chart Resolution?") ***This sets default timeframe of current chart, AND Creates CheckBox***

resCustom = input(title="Use Different Timeframe? Uncheck Box Above", type=resolution, defval="60") ***This defaults the timeframe to 60Min if you uncheck the CheckBox***

res = useCurrentRes ? period : resCustom ***This tells the "res" in lower part of code which one to use, the default chart timeframe, the 60 minute, or one from the drop down list.***

By understanding these you can follow the rest of code and pretty much apply to other indicators. I created checkboxes for every possible feature...that makes code look complex until you understand checkboxes, but applying the 3 items above should help with standard indicators.

I'm here if you have any questions.
+2 Reply
4apprentice08
2 years ago
Sorry but I am getting the following error:
"Inconsistent stackmap frames at branch target 42 in method Script.init()V at offset 20"

I have tried copying and save twice and changing chart timeframes (D, 240, 30, etc) with the same results. Please advise.
Reply
ChrisMoody PRO 4apprentice08
2 years ago
Sent you a PM...let me know how I can help
Reply
4apprentice08 ChrisMoody
2 years ago
Sorry but never got a PM. Not sure what to try. I have copied and pasted....just gives error
Reply
ChrisMoody PRO 4apprentice08
2 years ago
Just sent you another one
Reply
4apprentice08 ChrisMoody
2 years ago
Very strange....still did not get it. Did you see mine? I sent you 2 also.
Reply
4apprentice08 4apprentice08
2 years ago
Got it to work once I did a refresh of my chart. Must have been a hidden bug in TV. But now does exactly what I needed.
Reply
garyha
2 years ago
Awesome. Thank you ChrisMoody for the fine work.
I have a red-green vision thing going on so I tweaked things a bit, beautifully helpful.
Reply
ChrisMoody PRO garyha
2 years ago
Thanks man....I'm very visual and I find a lot of people hate the way my charts look as far as colors...I color code all of my indicators and they usually come down to Green = Buy...Red = Sell...Which is OK b/c I understand the scripts behind them. Eventually they will all be coded in to changing the color of the candlesticks so I rarely have lower indicators....

But always take my code and make it your own!!!!
Reply
cristian.d ChrisMoody
2 years ago
I m visual too, so I like your colourful indicators! Thank you for all your work and for sharing it here! You're an trading angel ;)
Reply
flibbr PRO
2 years ago
This looks AWESOME.. I'm going to try it out now.. I have a fantastic idea for a custom indicator... would you be interested in the idea if I pm you the theory ?
Reply
ChrisMoody PRO flibbr
2 years ago
Sure....
Reply
Thanks a whole bunch for this indicator... I wish I could apply all my oscillators to a different frame, it really enables a completely novel (and superior) way to plan trades across multiple frames. Looking forward to future releases and I'll be dissecting this to see if I can't replicate something similar with my favorite money flow
Reply
ChrisMoody PRO BuyOnPurple
2 years ago
You just use the standard money flow or do you have a custom one?
Reply
BuyOnPurple PRO ChrisMoody
2 years ago
I prefer Chaikin Money Flow, it's an oscillating moneyflow
Reply
ChrisMoody PRO BuyOnPurple
2 years ago
Here is a Link to Chaikin Money Flow w/ Multi TimeFrame Ability
http://pastebin.com/mihYhAhZ

I added a few options. I can customize further if I know if your prefer Lines or Histograms, and if you want Horizontal Lines at certain Values.

Chart Below Shows Indicator with Current Capabilities on Inputs Tab Via Check Boxes

snapshot
Reply
BuyOnPurple PRO ChrisMoody
2 years ago
Beautiful, thank you kind sir!
Reply
fcha PRO
2 years ago
Thank you!
Reply
ChrisMoody PRO fcha
2 years ago
FCHA...I'll always remember you...the first person I talked to on Trading view...

For you I have a great system I turned someone on to the other day...Let's do a Screen Share sometime and I will show it to you...
Reply
fcha PRO ChrisMoody
2 years ago
Thanks! It doesnt seems right when I copy this code.
Reply
ChrisMoody PRO fcha
2 years ago
there is a few links to code on this page...Are you talking about the code under the chart?
Reply
fcha PRO ChrisMoody
2 years ago
No, sorry that I sent this message to the wrong post. I m talking about Sling Shot code EURUSD.
Reply
4apprentice08
2 years ago
Looks like adding the option I requested for changing the timeframe is a real hit! Congrats.

My other request was if it is possible to have it change automatically to a pre-set multiple of the existing timeframe, e.g. if I am on 10 mins chart, show 60 mins MACD, or if on 240 mins, show the Day MACD, etc. In these examples I am using a 6X multiple. Other common multiples that some people use are 3X or 4X.
Reply
ChrisMoody PRO 4apprentice08
2 years ago
Including yours I had 3 major projects this week. Yours was major b/c before if it was Mult Time Frame it had to default to a specific time so basically every time you put it on a chart you had to adjust EVERY time you changed chart timeframes. There were a few minor items in there that had bugs that tech support fixed for us behind the scenes. My initial thought is No on the 6 times multiple.....but I thought this indicator was going to have to be made in to two different indicators after the first few days. So it's possible. Between this and another project I didn't get to find a resolution of the Opening Range issues. That is the only one that is important to me. Not sure if Tech support is working tomorrow or not....I'll ask but we might be looking at Tuesday or Wed of next week to find out 100%.

If it can be done we will get it done!!! And if it can't it will be a fixed issue in the future....and we will get it done then....Let's keep pushing the envelope...it's the only way to make great Advances!!!
Reply
4apprentice08 ChrisMoody
2 years ago
Here's hoping
Reply
ChrisMoody PRO 4apprentice08
2 years ago
And Yes...The Multiple Timeframe is HUGE...with the capability to have a indicator Default to whatever timeframe you on, but then allow you to change it by pressing a button...Gives us the ability to include feature in about every Indicator...Wouldn't have gotten done this quickly if it weren't for you ... So the community owes you one...
+1 Reply
4apprentice08 ChrisMoody
2 years ago
You're welcome for the inspiration/motivation...but you did all the hard work after all. This would not be possible if not for your efforts...here's to mutual effort. Good on you for your contribution!
+1 Reply
Hello - VERSION 2 OF INDICATOR

There is a know issue regarding If referencing a Higher TimeFrame the Histogram Doesn't show CORRECT COLORS

This is a link to Version 2 of Indicator. It is a partial fix and I'm working on a complete fix. The Values are Accurate.

Version 2 of Code:
http://pastebin.com/1aj724eH
Reply
rsparmar123
2 years ago
Holy smokes this is a gorgeous setup! Thanks a ton!
Reply
DanielPier
2 years ago
Wow, you are a genious! Tnks
Reply
ChrisMoody PRO DanielPier
2 years ago
Far from one...But Thanks....
Reply
bergaler PRO
2 years ago
Chris, i think this is the 4th of 5th script i've gotten from you tonight. You're the man!

Cheers!
Reply
ChrisMoody PRO bergaler
2 years ago
No Problem...Thanks
Reply
jonesesp PRO
2 years ago
Hey Chris, have you ever done the same with the Stochastic indicator?
Reply
ChrisMoody PRO jonesesp
2 years ago
No...I'm leaving this weekend to meet with some really talented coders...won't be back tip next Wednesday. If you PM me and remind me next week I'll get it done
Reply
jonesesp PRO ChrisMoody
2 years ago
ok will do....happy coding ;-)
Reply
ThisTejas
2 years ago
I was wondering how to do MTF in pine, I'll use your code as a primer, thank you for sharing
Reply
ChrisMoody PRO ThisTejas
a year ago
No Problem
Reply
pipCharlie
2 years ago
HI Chris, in the dropdown menu for Different Timeframes 4H is not available (or it could be just me). Is it possible to set the timeframe to 4H. Thanks in advance.
Reply
ChrisMoody PRO pipCharlie
a year ago
Those are the set time frames TradingView defaults to. Specific time frames can be coded.
Reply
thethirdconfig
2 years ago
Hey Chris, beautiful stuff you're putting out — thanks a bunch! I was wondering if you, or maybe someone else, now how to code it so the MACD crossover bar paints (when going with the trend)? That'd would be great when combined with the Slighshot system. Would love to hear from you.

A fan from Amsterdam, cheers!
Reply
ChrisMoody PRO thethirdconfig
a year ago
It's easy to do...you just have to set a rule. But you have to start thinking like a coder when your ask. Meaning the computer does EXACTLY what you tell it to...so how exactly do you define a trend?
Reply
great! thanks
Reply
ChrisMoody PRO SeaSide420
a year ago
Thanks for the comment.
Reply
Billhinge
a year ago
Hi Chris
I was wondering, is it possible or does such an indicator exist whereby you take multiple time frames say 1 week, day, 4h, 2h, 1h, 30m, 15m, 5m momentum and using superposition create an aggregate true macd. I had a go by linear addition but I assume this is an over simplification not taking into account phase of any macd waves. The rational I'm after is that during a day there may be long term buying/selling but hidden by short term buying/selling by retail

great scripts by the way, many thanks

Steve
Reply
Billhinge Billhinge
a year ago
PS I know you can plot multiple macd but I was thinking how do you add them to create a single line/histogram/area?
Reply
ChrisMoody PRO Billhinge
a year ago
Just saw this question..same as I mentioned above. Since your going down to a minute time frame. You would convert everything in to minutes and average them.
Reply
ChrisMoody PRO Billhinge
a year ago
Steve,

This is easy to do if you take the condition all the higher time frames have to either be crossing up or the MacD on the Higher time frames has to be positive (MacD above Signal Line) when the lower time frame crosses up....thus taking the trade with the trend.

What you specifically described...If I understand it correctly...would be taking all the time frames you mentioned and creating 1 macd based on those time frames. This would essentially be create a macd that is the average of all those time frames. Not sure how useful it would be. Since your lower time frame is in minutes. Take the amount of minutes in a week, then add the amount of minutes in a day (Depending on the market your trading), + 240 + 120 + 60 + 30 + 15 + 5...then divide that by the # of different time periods which is 7. I'm not going to do it but I think you would be looking at somewhere near a daily chart macd. But I might not be understanding you correctly.
Reply
Billhinge ChrisMoody
a year ago
many thanks Chris. I can do that
Reply
Billhinge ChrisMoody
a year ago
just checked what I did, I had already used minutes throughout and divided by 1.41 (RMS) but not averaged by 7 . Thanks I can write code but I wasn't sure about the logic involved in indicators ;-)
Reply
bingetrader
a year ago
Thank you for sharing this, it's outstanding!
Reply
tradersf
8 months ago
Hi. Great indicator!!!
Does it re-paint? I just had it show buy-sell-buy quiet rapidly, then I refreshed the page and it just showed the first buy. Should it really do this? Is that not repainting in some way?
Reply
ChrisMoody PRO tradersf
7 months ago
The signal can change on the current bar on the chart since it's still forming...the conditions can change intra-bar. However NOOO...it will not repaint after the bar has closed. I would never code anything that repaints historically. In my opinion that would be unethical...and unfortunately you would be surprised how many Trading Educators that sell Indicators do just that...there stuff looks amazing in hindsight...but trade with it live and it's a whole different story.

So on this indicator...Consider it only a signal once the current bar CLOSES....
Reply
tradersf ChrisMoody
7 months ago
Please correct me if I'm wrong but I find this indicator no different to using a standard MACD. I used it like this; 3 minute chart with 45min MACD setting. During the 45 minute bar, it whip-sawed and gave multiple signals (buy-sell-buy and so-on) until the 45 minute bar was closed. Then it used the earliest correct signal when refreshed. So this means ( as you have answered ) you have to wait for the bar to close to get the correct signal. Therefore it is of no special use because it gives the same signal if I was using a 45 minute chart and a standard MACD. I would have to wait for the 45 minute bar to close and then use the signal. Is this not correct? I can't see how this indicator is any different to the standard MACD.
Also I do agree with you that many of the strategies on this site re-paint and give false results.
Reply
ChrisMoody PRO tradersf
7 months ago
Your absolutely right. On a Standard MAD the signal isn't valid until the bar closes on whatever time frame your using it on.

The purpose for this indicator is 1 thing and only 1 thing. I had requests from many people to to (For Example) View the values of a Hourly or Daily MACD on let's say a 15 minute chart. So I coded it to show people how to.

I believe most of there thought process were if (Again just a example.) If the Daily MACD was Bullish....and then you get a pullback and entry to the upside on a 60 minute chart...they wanted to take that trade going with the Trend per se.

I just coded it per requests. That is what the indicator does....Nothing More....Nothing Less.

Hope that clarifies it for you.
Reply
tradersf ChrisMoody
7 months ago
I understand. Thanks for your reply.
Reply
ChrisMoody PRO tradersf
7 months ago
No problem....Thanks for the question
Reply
Fu-ChiaLin
5 months ago
Thank you~ ^_^b
Reply
dericksim
4 months ago
Hi Chris, is it possible to remove 30 and 45min and add in 4H? thanks in advance. Your indicators are superb! Cheers.
Reply
Ideas Scripts Chart
United States
United Kingdom
India
España
Italia
Brasil
Россия
Türkiye
日本
한국
Home Stock Screener 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 Billing Sign Out