HLC MACD

Here’s a MACD with a few subtle changes:

1) The price data used is (H+L+C)/3 rather than the close. I find this makes a subtle improvement in the display of divergences.

2) You can plot a second long time frame MACD line on the same chart (hidden by default).

3) The histogram bars are colored based on the relationship to the previous bar vice the standard above/below zero line coloring.

4) The color of the main MACD line is white when the slope is positive and purple when negative.

MACD HLC/3

# MACDHLC
# http://thinkscripter.wordpress.com
# thinkscripter@gmail.com
# Last Update 17 Jan 2009

declare lower;

input ShortTimeFrameFastLength = 7;
input ShortTimeFrameSlowLength = 28;
input STFMACDLength = 7;
input LongTimeFrameFastLength = 28;
input LongTimeFrameSlowLength = 112;
input LTFMACDLength = 5;

def fastAvg = ExpAverage(data = hlc3, length = ShortTimeFrameFastLength);
def slowAvg = ExpAverage(data = hlc3, length = ShortTimeFrameSlowLength);

plot STFValue = fastAvg - slowAvg;
STFValue.setLineWeight(2);
DEF STFslope = (STFValue-STFValue[1]);
DEF STFslopeColor = if(STFslope > 0.0,9,0);
STFValue.AssignValueColor(getColor(STFSlopeColor));
 
plot STFAvg = ExpAverage(data = STFValue, length = STFMACDLength);
STFAvg.SetDefaultColor(GetColor(8));

def LfastAvg = ExpAverage(data = hlc3, length = LongTimeFrameFastLength);
def LslowAvg = ExpAverage(data = hlc3, length = LongTimeFrameSlowLength);
 
plot LTFValue = LfastAvg - LslowAvg;
LTFValue.setDefaultColor(color.green);
LTFValue.hide();

plot Diff = STFvalue - STFavg;
diff.AssignValueColor(if diff >= diff[1] then Color.UPTICK else Color.DOWNTICK);
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetDefaultColor(GetColor(5));
 
plot ZeroLine = 0;
ZeroLine.SetDefaultColor(GetColor(0));
This entry was posted in Indicator and tagged , , . Bookmark the permalink.

5 Responses to HLC MACD

  1. ThinkScripter says:

    There was an errant semicolon in the script. It has been corrected.
    -Eric

  2. R. says:

    This is an excellent rendition of the MACD, Eric. I want to use this as a primary indicator, along with your Triple Stochastic – which is quite excellent also. I have 2 questions regarding the MACD, if you don’t mind ….

    1. Do you know why this indicator simply flatlines when using it on the EURO? I’m wondering if it’s the histogram. All I get is a small green and red straight line. There are other indicators that do this on the EURO too, no matter who programs them.

    2. Is there a way to change the colors of the “STFslopeColor” line to make them darker? They are so bright when using the standard “getColor” values, they’re hard to read. The line I’m talking about is this one …

    DEF STFslopeColor = if(STFslope > 0.0,9,0);

    I can code or recode several things, but I can’t seem to do this simple one. Do I need to “plot” it so I can change the colors?

    BTW, I’ve become a member and I’m VERY happy about it. You do superior and valuable work, and I’m only too pleased to contribute.

    R.

    • ThinkScripter says:

      I’m not sure why it doesn’t work on the EURO but will give it a look. Yes that is the line to change the colors of the line. It is very outdated in terms of thinkScript syntax since it was written some time ago. You can delete that line and the line following it and replace it with this single line of code and change the colors to suit you:

      STFValue.AssignValueColor(if STFslope > 0 then color.magenta else color.white);

      -Eric

      • R. says:

        Thank you very much, Eric. It’s much better on the eyes now.
        I truly appreciate your help — and your GREAT indicators!

        R.

  3. giom says:

    I’d like to get alerts when the slope gets white and when it goes back to purple..Anyone?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>