thinkScript: MACD Lines and Histogram

As far as I can see, the default studies in thinkorswim does not include one where both the MACD lines and histogram are plotted on the same pane. I’ve simply combined the code from the two studies.

 thinkscript-macd-lines-histogram-combined

# MACD Lines and Histogram
# Author: moolala.org
# Date: 04/23/2008

declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;

def fastAvg = Ema2(data = close, "smoothing factor" = 2 / (1 + fastLength));

def slowAvg = Ema2(data = close, "smoothing factor" = 2 / (1 + slowLength));

plot Value = fastAvg - slowAvg;

def nextAvg = ExpAverage(data = Value, MACDLength);

plot Avg = nextAvg[1];
plot ZeroLine = 0;

Avg.SetDefaultColor(Color.Red);
Value.SetDefaultColor(Color.White);
ZeroLine.SetDefaultColor(GetColor(5));

plot Diff = value - nextAvg[1];

diff.AssignValueColor(if Diff >= 0 then Color.UPTICK else Color.DOWNTICK);
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
 
Advertisement

No comments yet

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.