ITMScript
Colour a MACD histogram by its sign
Draw a MACD histogram in green above zero and red below, with the MACD and signal lines over it.
Draw the MACD histogram in one colour above zero and another below it.
//@itmscript 2
study("MACD histogram", overlay=false)
fastLen = input.int(12, "Fast", min=2, max=100)
slowLen = input.int(26, "Slow", min=3, max=200)
sigLen = input.int(9, "Signal", min=2, max=100)
[macdLine, signalLine, hist] = ta.macd(close, fastLen, slowLen, sigLen)
plot(hist, "Histogram", color=hist >= 0 ? color.green : color.red, width=1, style=histogram)
plot(macdLine, "MACD", color=color.blue, width=2, style=line)
plot(signalLine, "Signal", color=color.orange, width=1, style=line)
hline(0, "Zero", color=color.gray, style=dotted)What you see
The MACD pane shows a histogram, a blue MACD line and an orange signal line. A histogram bar is green when it is at or above zero and red when it is below. The histogram has no bars until the signal average has enough history.
The colour follows the sign of the histogram. It does not say whether the histogram is growing or shrinking. A plot may take a condition that picks between two colours. Outputs says where that is allowed.
Change these inputs
- Fast. The window of the fast average, from 2 to 100 bars.
- Slow. The window of the slow average, from 3 to 200 bars. Keep it above the fast window.
- Signal. The window of the average of the MACD line, from 2 to 100 bars. A shorter window makes the signal line follow the MACD line more closely.