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.
# 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