4 Coloured MACD Pine Script: Main-Line Columns and Exact Color States
This 4 Coloured MACD plots the MACD main line as columns. It colors that value using its sign and its change from the previous bar. It does not plot MACD minus a signal line, so its columns are a different quantity from the conventional MACD histogram.
Inspect the Pine ScriptWhich MACD output is plotted?
The helper takes the first result from ta.macd: M = EMA(close,12) − EMA(close,26). Its signal and histogram outputs are discarded. The internal signal argument 9 does not change that first result. The previous comparison value is calculated from close[1] with the same lengths; on ordinary continuous valid data, this is the one-bar-shifted main line.
By contrast, the conventional MACD histogram is H = M − EMA(M,9). For a synthetic state with M = 1 and signal = 2, these columns are above zero at +1 while the conventional histogram is below zero at −1. Calling both drawings a histogram describes their appearance, not formula equivalence.
TradingView’s MACD documentation distinguishes the main, signal and histogram series. Its standard display also has direction-sensitive histogram colors; four colors are not proof of a new predictive calculation.
The exact four branches include ties and zero
| Current M | Comparison with previous M | Color |
|---|---|---|
| Strictly positive | Higher | Lime #00FF00 |
| Strictly positive | Equal or lower | Green #008000 |
| Zero or negative | Lower | Maroon #800000 |
| Zero or negative | Equal or higher | Red #FF0000 |
Positive ties are green; negative ties are red. Zero belongs to the nonpositive branch: a drop from +1 to 0 is maroon, a rise from −1 to 0 is red, and unchanged zero is red. A zero-height column may not be visibly distinguishable on the chart. Red cannot occur at a strictly positive value in this implementation.
If the previous value is unavailable, the strict comparison is false. This chooses the fallback branch rather than establishing an observed change. Color does not supply a probability, identify actual buy/sell volume, or mean that the current price has moved in the same direction.
Check a complete color sequence
Given a valid previous M of 1, feed these synthetic current values into the color conditions:
| Current values in order | Colors in order |
|---|---|
| 2, 2, 1, 0 | Lime, green, green, maroon |
| −1, −2, −2, −1, 0 | Maroon, maroon, red, red, red |
The green second bar is a tie, not a falling value. The red −2 tie is not an upward turn. Red at −1 follows an increase but M is still negative. These cases matter if an adaptation treats every color transition as a trade event: a rule requiring a strict rise is different from a rule accepting the red color state.
Current-versus-previous does not mean an extra bar of delay
The calculation compares the current bar with an already available previous value. It can change color during the current bar as close changes; it does not wait one additional bar to detect that comparison. A closed-bar alert would intentionally wait for the current bar to finish. That confirmation policy differs from waiting for two consecutive same-color bars.
A current lime state and two immediately preceding green states cannot also be three consecutive lime states ending now. If you want a sequence such as an earlier lime run, a green pause and a new lime event, specify the ordered bars or a state machine. The copied plotting code implements no such strategy.
Source parameters and product controls are different
This standalone example fixes lengths at 12 and 26, source at close, and column linewidth at 3. There are no input declarations, alert conditions, signal-line plots or strategy orders. The complete helper is included below so the source is self-contained.
Pineify’s Visual Editor configuration separately registers MACD 4C under Momentum, with fast/slow settings and four drawing colors. Those product settings are not automatically settings inputs in the copied script. For an AI Coding Agent adaptation, explicitly request the inputs and alert timing you need, then inspect the resulting code.
Different EMA lengths change the calculation. No universal lead of two or three bars, best timeframe or measured win rate is established by this page. To test a trading rule, define its event, exits, fills, costs and evaluation period independently of the color labels.
Pine Script v6: implementation and limits
The helper is included in full and the color expression retains all four original branches, including zero and tie behavior. It computes the main line twice, using close and close[1], and discards both signal and histogram results. The live plot has no bar-close gate.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Pineify
//======================================================================//
// ____ _ _ __ //
// | _ \(_)_ __ ___(_)/ _|_ _ //
// | |_) | | '_ \ / _ \ | |_| | | | //
// | __/| | | | | __/ | _| |_| | //
// |_| |_|_| |_|\___|_|_| \__, | //
// |___/ //
//======================================================================//
//@version=6
indicator(title="4 Coloured MACD", overlay=false, max_labels_count=500)
p_ta_macd4c(simple int fastMA, simple int slowMA) =>
[currentValue, _, _] = ta.macd(close, fastMA, slowMA, 9)
[previousValue, _, _] = ta.macd(close[1], fastMA, slowMA, 9)
[currentValue, previousValue]
[currMacd, prevMacd] = p_ta_macd4c(12, 26)
hline(0, title="MACD 4C - Zero Line", color=color.new(#787B86, 50))
plotColor = currMacd > 0 ? (currMacd > prevMacd ? color.rgb(0, 255, 0) : color.rgb(0, 128, 0)) : (currMacd < prevMacd ? color.rgb(128, 0, 0) : color.rgb(255, 0, 0))
plot(currMacd, title="MACD 4C - 4C MACD", style=plot.style_columns, color=plotColor, linewidth=3)
Specify a checkable adaptation in Pineify
Ask Pine Script AI Coding Agent to add fast/slow inputs and alerts for clearly defined strict comparisons or color transitions. State how zero, ties and unconfirmed bars should behave. Validate the generated source and compare the color sequence above before evaluating a trading rule.
Open Pine Script AI Coding AgentEducational indicator analysis. No measured trading performance is established here. Syntax validation does not prove formula equivalence, execution assumptions or profitability.