Video: How To Use MACD: Crossovers And Divergences Explained
Creator: Verified Investing
Original Video: Watch the original video
Difficulty: Intermediate
The Big Idea
MACD compares a faster moving average with a slower one, then compares that difference with its own smoothed history. It helps describe changing momentum, but it does not independently establish an entry, exit, or profitable strategy.
Verified Investing demonstrates two uses: signal-line crossovers and divergence between price swings and MACD. This guide explains the calculations, separates those signals from predictions, and provides a Pine Script experiment with explicit risk and confirmation rules.
Three Calculations Explain the Display
| Component | Common calculation | What it describes |
|---|---|---|
| MACD line | 12-period EMA of close minus 26-period EMA of close | Separation between the faster and slower averages |
| Signal line | 9-period EMA of the MACD line | A smoothed reference for that separation |
| Histogram | MACD line minus signal line | Distance between the two indicator lines |
The signal line is not simply a nine-period EMA of price. It smooths the MACD values themselves. Periods mean chart bars: the daily chart uses daily observations, while a 15-minute chart uses 15-minute observations.
These formulas match the usual EMA-based configuration described in TradingView’s MACD documentation (paid link). Check the selected moving-average types and lengths rather than assuming every customized MACD uses the same calculation.
A Signal Cross and a Zero Cross Are Different
A bullish signal-line crossover occurs when MACD moves from at or below its signal line to above it. A bearish crossover does the reverse. A zero-line crossing instead describes when the faster price EMA moves above or below the slower price EMA.
Suppose MACD is −1.20 and the signal line is −1.50. The histogram is +0.30: MACD is above its signal even though both lines remain below zero. That can describe improving momentum while the faster average is still below the slower one.
Conversely, a bearish signal crossover above zero can occur during a pullback within a broader rise. A crossover is a change in the relationship between smoothed values, not proof that the entire trend has reversed.
The source compares bullish and bearish MACD crosses with golden and death crosses. This is an analogy; a MACD-versus-signal cross is not the same event as two selected price moving averages crossing.
Read Histogram Values Before Colors
A positive histogram means MACD is above its signal; a negative histogram means it is below. A shrinking positive bar means that positive separation is narrowing. It does not necessarily mean price is already falling.
Colors and shades are configurable and may distinguish increasing from decreasing histogram values. Inspect the sign and settings rather than treating any color change as a crossover.
The presenter hides the histogram to make the lines easier to see. That changes the display, not the underlying information. A histogram crossing zero and a MACD signal-line cross express the same relationship.
Divergence Compares Matching Swing Locations
| Regular divergence | Price | MACD at corresponding price swings | Interpretation |
|---|---|---|---|
| Bearish | A higher high | A lower reading | The new price high has weaker measured momentum |
| Bullish | A lower low | A higher reading | The new price low has weaker measured downside momentum |
The transcript’s bullish example mentions highs and lower highs, but the conventional regular bullish comparison uses price lows. Align the MACD readings with the price swing timestamps instead of pairing unrelated indicator turns.
In an original bullish example, price makes lows of 50 and 48, while MACD at those points is −2.0 and −1.2. Price has moved lower with a less negative momentum reading. That warns that downside momentum has changed; it does not establish the next move’s direction or timing.
Strong trends can continue through repeated divergence. Treat divergence as a condition to evaluate alongside a defined trigger, rather than automatically shorting every higher high or buying every lower low.
Confirmation Introduces a Real Delay
A swing low that requires three later bars to confirm is known only after those bars arrive. On a daily chart, that is a substantial delay. A line drawn back to the low can make the signal appear earlier than it was available.
A repeatable rule must specify pivot strength, how the MACD values are sampled, and how long confirmed divergence remains relevant. It must also define what triggers the actual order: a crossover, a price break, or another event.
The source’s selected large moves illustrate possibilities, not the return from a complete mechanical trading record. The transcript’s ticker references are also inconsistent, so this guide does not infer the exact demonstration instrument or reconstruct its quoted moves.
MACD Does Not Supply the Entire Exit Plan
The presenter notes that technical levels may be needed for targets. A crossover alone leaves several choices unresolved: stop placement, position quantity, profit target, exit on the opposite cross, and whether to reverse immediately.
In an original example, a long fills at 100 with a stop at 97. Planned price risk is three units; a 2R target is 106. If it instead fills at 101 with the same stop, risk becomes four and a fill-based 2R target becomes 109. Leaving the old target at 106 offers only 1.25R.
Even a correctly placed stop cannot guarantee the planned loss through a gap. Position size should account for instrument value, executable quantity increments, and costs.
Pine Script Research Strategy
Expand the complete Pine Script research strategy
//@version=6
strategy("MACD crossovers with confirmed divergence filter", overlay=true,
initial_capital=25000, pyramiding=0, margin_long=100, margin_short=100,
commission_type=strategy.commission.percent, commission_value=0.01,
slippage=2, calc_on_order_fills=true, calc_on_every_tick=false,
process_orders_on_close=false)
fast = input.int(12, "Fast EMA", minval=1)
slow = input.int(26, "Slow EMA", minval=2)
signalLength = input.int(9, "Signal EMA of MACD", minval=1)
useDivergence = input.bool(false, "Require recent confirmed regular divergence")
pivotBars = input.int(3, "Price pivot left/right bars", minval=1)
divAge = input.int(20, "Divergence validity after confirmation", minval=1)
useZero = input.bool(false, "Require long MACD > 0 / short MACD < 0")
allowShorts = input.bool(false, "Allow shorts; verify borrow")
stopBars = input.int(5, "Stop swing lookback", minval=1)
reward = input.float(2, "Target R from actual fill", minval=0.1)
cashRisk = input.float(100, "Estimated cash risk before costs", minval=1)
qtyStep = input.float(1, "Quantity increment", minval=0.000001)
maxQty = input.float(1000, "Maximum quantity", minval=0.000001)
if barstate.isfirst
if not chart.is_standard
runtime.error("Use standard candles.")
if fast >= slow
runtime.error("Fast EMA must be shorter than slow EMA.")
[macd, signal, histogram] = ta.macd(close, fast, slow, signalLength)
bullCross = ta.crossover(macd, signal)
bearCross = ta.crossunder(macd, signal)
pivotLow = ta.pivotlow(low, pivotBars, pivotBars)
pivotHigh = ta.pivothigh(high, pivotBars, pivotBars)
stopLow = ta.lowest(low, stopBars)
stopHigh = ta.highest(high, stopBars)
varip float previousLow = na
varip float previousLowMACD = na
varip float previousHigh = na
varip float previousHighMACD = na
varip int bullDivBar = na
varip int bearDivBar = na
varip float tradeStop = na
varip float tradeTarget = na
varip float seenPosition = 0.0
varip int lastFillBar = na
fillPass = strategy.position_size != seenPosition
seenPosition := strategy.position_size
if fillPass
lastFillBar := bar_index
if strategy.position_size != 0
distance = strategy.position_size > 0 ? strategy.position_avg_price - tradeStop : tradeStop - strategy.position_avg_price
if distance > 0
tradeTarget := strategy.position_avg_price + (strategy.position_size > 0 ? 1 : -1) * reward * distance
else
tradeTarget := na
strategy.close_all(comment="Fill beyond stop", immediately=true)
if not fillPass and barstate.isconfirmed
// Compare MACD sampled at the SAME price-pivot bars.
if not na(pivotLow)
currentMACD = macd[pivotBars]
if not na(previousLow) and pivotLow < previousLow and currentMACD > previousLowMACD
bullDivBar := bar_index
previousLow := pivotLow
previousLowMACD := currentMACD
if not na(pivotHigh)
currentMACD = macd[pivotBars]
if not na(previousHigh) and pivotHigh > previousHigh and currentMACD < previousHighMACD
bearDivBar := bar_index
previousHigh := pivotHigh
previousHighMACD := currentMACD
bullDivOK = not useDivergence or (not na(bullDivBar) and bar_index - bullDivBar <= divAge)
bearDivOK = not useDivergence or (not na(bearDivBar) and bar_index - bearDivBar <= divAge)
// Opposite cross exits but does not reverse the position immediately.
if strategy.position_size > 0 and bearCross
strategy.close("L", comment="Opposite crossover")
if strategy.position_size < 0 and bullCross
strategy.close("S", comment="Opposite crossover")
if strategy.position_size == 0 and (na(lastFillBar) or bar_index > lastFillBar)
wantLong = bullCross and bullDivOK and (not useZero or macd > 0)
wantShort = allowShorts and bearCross and bearDivOK and (not useZero or macd < 0)
if wantLong or wantShort
candidateStop = wantLong ? stopLow - syminfo.mintick : stopHigh + syminfo.mintick
distance = math.abs(close - candidateStop)
unitRisk = distance * syminfo.pointvalue
quantity = unitRisk > 0 ? math.floor(math.min(maxQty, cashRisk / unitRisk) / qtyStep) * qtyStep : 0
if quantity >= qtyStep
tradeStop := candidateStop
tradeTarget := na
if wantLong
strategy.entry("L", strategy.long, qty=quantity)
strategy.exit("L-bracket", "L", stop=tradeStop)
else
strategy.entry("S", strategy.short, qty=quantity)
strategy.exit("S-bracket", "S", stop=tradeStop)
if strategy.position_size > 0 and not na(tradeTarget)
strategy.exit("L-bracket", "L", stop=tradeStop, limit=tradeTarget)
if strategy.position_size < 0 and not na(tradeTarget)
strategy.exit("S-bracket", "S", stop=tradeStop, limit=tradeTarget)
plot(strategy.position_size != 0 ? tradeStop : na, "Stop", color=color.red, style=plot.style_linebr)
plot(strategy.position_size != 0 ? tradeTarget : na, "Target", color=color.green, style=plot.style_linebr)
plot(macd, "MACD data", display=display.data_window)
plot(signal, "Signal data", display=display.data_window)
plot(histogram, "Histogram data", display=display.data_window)
The following original strategy tests MACD crossovers, optionally requiring recent confirmed regular divergence or the appropriate zero-line position. Default entries are long-only; shorts can be enabled after checking the instrument’s borrow and trading restrictions.
Our added rules: divergence uses adjacent confirmed price pivots with three bars on either side and MACD sampled at those same pivot bars. It remains eligible for 20 bars after confirmation. The stop uses the previous five bars including the signal candle, plus one tick. The default target is 2R from the actual fill.
An opposite crossover exits an open position. It does not automatically reverse it: another qualifying crossover while flat is required. The source does not specify these numerical risk, expiry, or execution rules, so this is a baseline experiment rather than its exact strategy.
Execution QA
Run on standard candles with enough history for the averages and pivots. There are no higher-timeframe requests. Divergence becomes available on the pivot’s confirmation bar, not its earlier turning-point bar; a crossover on that confirmation bar is eligible because both conditions are then known.
Signals are evaluated at completed candle closes and market entries normally fill at the next bar’s open. The initial protective stop is submitted alongside the entry. A fill-only recalculation sets the target from actual average entry and the frozen stop without using that fill bar’s completed high or low for a new setup. A fill beyond the stop prompts an immediate simulated exit.
Stops and targets remain fixed throughout the position. An opposite-cross market exit normally fills on the next available tick; the bracket remains active meanwhile. The next entry requires a later eligible cross, so the model intentionally misses some immediate reversals.
Quantity is estimated from the signal close and can exceed the intended cash risk after a gap. Set quantity increments and limits for the product. Cash risk and instrument profit-and-loss values must use the same currency; conversion is not modeled. The 100% margin setting can prevent otherwise qualifying orders from filling.
Commission defaults to 0.01% per fill and slippage to two ticks, adjustable in Strategy Properties. Spreads, borrow costs, funding, and every venue’s order restrictions are absent. There is no session flatten. Same-bar stop and target outcomes depend on broker-emulator assumptions and should be inspected with Bar Magnifier where available.
The code has been reviewed for its stated logic but has not been compiled or backtested in TradingView. It does not test the source’s hand-drawn targets, independently selected indicator pivots, or sponsored products. No win rate or profitability result is claimed.
Backtest Lab
| Comparison | Change one input | Evaluate |
|---|---|---|
| Basic trigger versus divergence | Toggle the divergence requirement | Net expectancy, sample size, missed opportunities |
| Signal cross versus broader direction | Toggle the zero-line filter | Whether reduced participation improves outcomes |
| Swing confirmation | Change pivot strength | Delay and sensitivity to swing definitions |
| Execution stress | Increase commission and slippage | Whether frequent crosses survive friction |
Keep instruments and dates consistent, include every qualifying losing trade, and reserve unseen data for validation. Ranges often produce repeated crosses; selected trending examples are not a fair test of the indicator. The transcript’s closing promotion is separate from the MACD lesson, and its fees, availability, and leverage claims are not evaluated here.
Final Takeaway
MACD describes relationships between smoothed price measurements. Crossovers identify a change relative to the signal line, while divergence identifies a mismatch between price swings and measured momentum. Both become useful research inputs when confirmation timing, entries, exits, and costs are defined explicitly.
Risk Disclosure: This material is for educational and research purposes only and is not financial or investment advice. Trading can result in substantial losses. Backtests are hypothetical, depend heavily on their assumptions, and cannot reproduce every aspect of live execution. Commissions, spreads, slippage, liquidity, gaps, order behavior, market regime changes, and discretionary decision-making can materially affect real-world results. Leveraged products and short selling carry additional risks. Historical results do not guarantee future performance.
This article is an independent educational companion to the video and is not affiliated with, sponsored by, endorsed by, or authorized by Verified Investing or its sponsors.