Skip to main content
On this page

MACD on TradingView: Settings, Signals, and Custom Script Checks

· 9 min read
Pineify Team
Pine Script and AI trading workflow research team

MACD measures the difference between two moving averages and compares that difference with a smoothed signal line. On TradingView, the useful choice is not a universally “best” script: it is a calculation and signal definition that you can reproduce on the intended chart.

This guide explains the standard settings, distinguishes crossover and divergence conditions, and shows what to check before adding filters, higher-timeframe data or alerts. It does not report an independently measured advantage for any configuration.

Best MACD Indicator TradingView: Complete Guide to Settings, Strategies, and Top Scripts

Formula and components​

With close as the source and exponential moving averages selected, the familiar settings are:

  • MACD line = 12-bar EMA of close minus 26-bar EMA of close.
  • Signal line = 9-bar EMA of the MACD line.
  • Histogram = MACD line minus signal line.

TradingView's MACD documentation also describes source and moving-average-type inputs. Changing to SMA produces a different calculation; it is not inherently smoother or more profitable in every situation. Save both MA types with the three lengths when comparing charts.

A positive MACD line means the selected fast average is above the slow average. It does not mean the current candle rose. A positive histogram means MACD is above its signal line. If that histogram shrinks, their separation is narrowing; price can still rise. These are descriptions of the calculation rather than forecasts of a reversal.

MACD is expressed in the price units of its source. A reading of 2 on a high-priced stock is not directly comparable with 0.002 on a currency pair. Use consistent instruments or a deliberately normalized measure for cross-market comparisons.

Add MACD and choose settings​

Open Indicators, search for Moving Average Convergence Divergence, and select the built-in study. In its settings, record the source, fast length, slow length, signal length, oscillator MA type and signal MA type. Also record the chart exchange, interval, session and candle type.

CandidateWhat changesWhat to examine
12/26/9Standard reference lengthsBaseline timing and repeated crossings
8/17/9Shorter fast and slow averages than the referenceWhether earlier changes survive costs and extra turnover
34/144/9Longer fast and slow averagesWhether added delay misses entries or reduces churn
SMA-based variantDifferent weighting of the same price historyCompare values and timing without attributing an automatic advantage

These are test candidates, not recommendations for particular markets. Twelve bars on a five-minute chart and twelve bars on a daily chart represent different observations. Faster settings can change sensitivity, but no rule here establishes that all crypto or intraday trading benefits from shorter lengths.

Three signal definitions to keep separate​

Signal-line crossover​

A bullish crossover occurs when MACD moves from at or below its signal line to above it. A bearish crossover is the reverse. “MACD is above its signal line” is a persistent state, not a new crossover on every bar.

Because the histogram is their difference, MACD crossing its signal line and the histogram crossing zero describe the same event when inputs and evaluation timing match. They are not two independent confirmations. Requiring histogram growth over several bars adds a different condition; specify those bars before testing it.

For a reproducible example, evaluate a bullish crossover at the bar close, then define the permitted entry time, exit, size and costs. A chart marker alone omits all of these decisions. An intrabar crossover may disappear before the close.

MACD zero-line crossover​

When MACD crosses zero, the fast and slow averages cross each other. This is distinct from the signal-line crossover. Their order depends on the path of the series; the zero-line event is not guaranteed to arrive later or be more reliable.

You could test a rule that only permits signal-line entries while MACD is above zero. That may eliminate both losing and profitable trades. Compare the complete trade distribution and drawdown instead of assuming fewer signals means better signals.

Divergence​

Bullish divergence pairs a lower price low with a higher MACD low. Bearish divergence pairs a higher price high with a lower MACD high. State whether the oscillator comparison uses the MACD line or histogram; they can identify different events.

A usable procedure is to choose pivot left/right confirmation lengths, match the price and oscillator pivots under a specified timing rule, and record when the second pivot was confirmed. If confirmation needs later bars, an entry at the earlier pivot price is unavailable. Decide what ends the setup: a price break, another pivot, a time limit or an invalidation level.

Divergence can persist during a strong trend. It does not establish a fixed win rate, and a target of 1.5 or 2.5 times the initial risk cannot make an untested entry profitable by itself. Costs, stop execution and the frequency of losses matter.

Alternatives and companion studies​

StudyRelevant distinction from MACDBoundary
AlphaTrend by KivancOzbilgicUses ATR with MFI, or an optional RSI calculation when volume is unavailable; signals compare its line with its value two bars earlierIt is not a CCI-based MACD variant; potential and confirmed alarms differ
WaveTrend by LazyBearOscillator and signal-line crossings relative to reference bandsNo evidence here establishes that it consistently leads MACD by one or two bars
VWAPVolume-weighted price from a defined anchor or sessionPrice above VWAP does not reveal who is buying
Stochastic Momentum IndexMeasures the close relative to the midpoint of its recent range with smoothingExtreme readings describe the calculation, not guaranteed reversals

RSI and MACD share price inputs. Requiring RSI above 30 or another threshold can be tested, but their agreement does not prove independent confirmation. Volume adds activity information where the feed supplies it; above-average volume does not identify institutional intent. Keep filters only if their contribution survives a fair comparison.

Custom MACD scripts and Pineify​

The following existing Pine fragment calculates standard EMA-based MACD and two crossover conditions. It is an excerpt to place inside an appropriate script, not a complete indicator or strategy: it has no version declaration, script declaration, plots, order handling or risk rules.

// Basic MACD logic in Pine Script
[macdLine, signalLine, histLine] = ta.macd(close, 12, 26, 9)

// Define a potential long entry condition
longCondition = ta.crossover(macdLine, signalLine)

// Define a potential short entry condition
shortCondition = ta.crossunder(macdLine, signalLine)

Custom script categories include higher-timeframe displays, automatic divergence detection and MACD plus RSI conditions. Match the exact publication, author, source access and version; a generic title does not identify one tested implementation.

Pineify provides MACD inputs for source and the three lengths, and outputs for the MACD line, signal and histogram. Its separate CM Ultimate MACD MTF configuration includes a current-chart-resolution switch and a custom timeframe. Choose the relevant preset and inspect the generated script. Those controls do not imply that every divergence or timing rule is automatically available in one visual form, or that generated code is error-free.

Pineify Website

Higher-timeframe analysis without future information​

One hypothesis is to allow hourly bullish crossovers only when the last confirmed daily MACD is above zero. Record the daily boundary and time zone, and use the value available at the hourly decision time. A still-open daily bar can change during the session. Its final value cannot be assigned retrospectively to earlier hourly decisions.

TradingView's repainting guidance explains these historical/realtime differences. Compare live observations with the reloaded chart. A higher-timeframe filter changes exposure and sample size; it does not guarantee better results.

Alerts, backtests and execution​

Choose the intended condition in TradingView's alert dialog and check frequency, expiry and account eligibility. For a closed-bar rule, use timing consistent with that rule. When changing the script or inputs, recreate affected alerts so they use the intended settings.

A webhook sends an HTTP request to a configured receiver. It does not itself provide broker authentication, order validation or execution. TradingView's webhook documentation describes delivery requirements and limitations. An execution service must handle duplicates, rejected orders, sizing and missing acknowledgements.

For testing, keep the same data window, costs and order timing across candidates. Separate the period used to select settings from a later evaluation period. Include spread, slippage and commissions appropriate to the instrument. Inspect trade count, exposure, drawdown and net outcomes rather than a crossover “success rate” with no definition. A risk percentage alone does not prevent gaps or accumulated losses.

Frequently asked questions​

What are the best MACD settings for day trading?​

No universal setting is established here. Treat 12/26/9 as a reference and test a small, stated set of alternatives with the same execution and cost assumptions.

Is histogram confirmation independent of a crossover?​

A histogram zero crossing is the same algebraic event as the MACD/signal crossover. A separate multi-bar histogram rule is an additional filter, whose value needs testing.

Can MACD automate trades?​

It can define conditions used by strategies and alerts. Live orders require a supported execution arrangement and risk controls; indicator signals alone do not place broker orders.

Does MACD work on crypto?​

It can be calculated from a crypto price series. That establishes availability, not profitable performance. Specify the exchange, instrument, trading costs and confirmation timing.

Which matters more: divergence or a zero-line crossing?​

They answer different questions and have different confirmation requirements. Compare their defined trading rules rather than assuming either is inherently stronger.