← Back to Home
Trading Signal / Indicator
🌊

MACD β€” Moving Average Convergence Divergence

A momentum indicator that doubles as a trend signal.

Start Automating Free β†’

Want to automate this strategy? Try auto-Trading free β€” no credit card required.

MACD β€” Moving Average Convergence Divergence chart

Overview

What is MACD β€” Moving Average Convergence Divergence?

The MACD (Moving Average Convergence Divergence) is one of the most widely used technical indicators, serving as both a trend-following and momentum tool. Developed by Gerald Appel in the late 1970s, it is built from three components: the MACD line (difference between the 12-period EMA and 26-period EMA), the signal line (9-period EMA of the MACD line), and the histogram (MACD line minus signal line).

The primary trading signals are: (1) MACD line crosses above/below the signal line β€” a bullish/bearish signal; (2) MACD crosses above/below zero β€” the "centreline crossover," confirming trend direction; and (3) divergence between MACD and price β€” one of the most reliable reversal signals.

The histogram is particularly valuable for gauging momentum: expanding bars indicate increasing momentum in the direction of the trend, while shrinking bars suggest the move is losing steam before a potential reversal. A histogram that peaks and begins to contract is an early warning of a signal line crossover ahead.

MACD works best as a trend-confirmation tool on timeframes of 1H and above. On lower timeframes it generates excessive noise. Combining MACD signals with structure analysis (support/resistance) and volume confirmation significantly improves signal quality.

How It Works in auto-Trading

Automate It

auto-Trading computes the MACD line, signal line, and histogram values bar by bar. In the strategy builder, users can trigger on: MACD/signal crossovers, centreline crossovers, histogram direction changes, or divergence events. The divergence detector compares price swing extremes with MACD histogram extremes over a configurable lookback period.

Try Free β†’

Strategy Code

Pick a script below, copy it, and use it on your chart.

Pine Script (TradingView)

This is a TradingView Pine Script example for this indicator. Paste it into the TradingView Pine Editor, add it to your chart, and adjust inputs for your market and timeframe.

//@version=6
strategy("MACD β€” Moving Average Convergence Divergence", overlay=true)
fast = input.int(12, "Fast")
slow = input.int(26, "Slow")
sig = input.int(9, "Signal")

Get full strategy code access

Enter your email address and full name to unlock this strategy code.

ThinkScript (thinkorswim)

This is a thinkorswim ThinkScript example for this indicator. Open thinkorswim, create a custom study, paste the script, and apply it to your chart.

def macd = MACD()."Value";
def signal = MACD()."Avg";
def buySignal = macd crosses above signal;
def sellSignal = macd crosses below signal;
AddOrder(OrderType.BUY_AUTO, buySignal, close, 1, Color.GREEN, Color.GREEN, "MACD Buy");

Get full strategy code access

Enter your email address and full name to unlock this strategy code.

Ready to automate MACD β€” Moving Average Convergence Divergence?

Join thousands of traders who use auto-Trading to execute this strategy automatically, 24/7.

Get Started Free β†’

All Strategies & Signals

Continue Learning

Trading Strategies

Trading Signals & Indicators