Indicator · Pine Script v6 · Own pane

MACD

by YooooungLee

This indicator calculates and plots the standard Moving Average Convergence Divergence oscillator in a separate pane.

View on GitHub

GitHub stars4on the repository
Pine versionv6current
Lines of code36
Settings4inputs
LicenceApache-2.0
Last update10 months ago29 Dec 2025

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

36 lines of Pine Script v6 from Quant-code/indicator/MACD.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

MACD.pine
//@version=6
//@author=Yooooounglee


//note:20250505 home
//1. Appel的MACD指标,他的交易理解是:市场的交易是脉冲式的,缩减的脉冲暗示调整近在眼前,而扩张的脉冲暗示市场即将继续上涨。
//2. 他类比高尔夫球的运动,抛物线轨迹,从飞行的角度和速度判断落点,而球在上升过程中速度逐步减少,斜率逐渐归零,然后开始下降。
//3. 综合,他关注的是动量的变化,是一个短期的趋势指标,缺少对长期和总体的把握。
//4. MACD是一个双均线系统,所以理论上可以追踪长期走势,但他本人没有用这个的描述长期变化的想法。
//5. 只是推断,Appel设计指标的初衷,可能只是为了提早的发现金叉和死叉。
//6. 都市传说,其中的参数MACD(12,26,9)美国一周六天班,交易六天,12是两周,26是一个月只放四天假,鉴定为假。Appel自己的说法是,纯交易经验。拍脑袋来的。
//7.1Appel给了一个建议,“长均线是短均线的2-3倍较好”,短期线的时间跨度越短,则越容易捕捉到短期的价格变化,但是也会增加噪声。
//7.2信号线DEA的参数建议设置到3-9,他是MACD的移动指数平均线。
//8. 他给了三组建议的参数,分别是(12,26,9),(5,13,9),(19,39,9),其中第一个是最常用的,第二个是短线交易者的选择,第三个是中线交易者的选择。


// 定义指标
indicator("MACD", shorttitle="MACD", overlay=false)
// 传输参数
fastLength = input.int(12, title="Fast Length")
slowLength = input.int(26, title="Slow Length")
signalSmoothing = input.int(9, title="Signal Smoothing")
src = input.source(close, title="Source")

// MACD 计算过程
fastMA = ta.ema(src, fastLength)
slowMA = ta.ema(src, slowLength)
DIF = fastMA - slowMA
// DEM线,也叫信号线,是DIF的移动指数平均线,用于平滑DIF线,使DIF线更平滑,便于观察
DEM = ta.ema(DIF, signalSmoothing)
MACD = DIF - DEM

// 绘图
plot(DIF, color=color.white, title="DIF线", linewidth=2)
plot(DEM, color=color.yellow, title="DEM线", linewidth=2)
plot(MACD, color=MACD >= 0 ? color.red : color.green, style=plot.style_histogram, title="MACD柱状图", linewidth=2)

Overview

MACD computes a fast exponential moving average and a slow exponential moving average from the chosen price source, taking the difference as the DIF line. An exponential smoothing of DIF forms the signal line, while the difference between them plots as a color-coded histogram. Users can adjust the fast length, slow length, signal smoothing length, and source price. The script plots oscillator lines without built-in alert conditions, trading signals, or automated execution rules.

Details

Published by

YooooungLee on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Oscillators & momentum, Moving averages, Trend

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Fast Lengthint12fastLength
Slow Lengthint26slowLength
Signal Smoothingint9signalSmoothing
Sourcesourceclosesrc
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Beep Boop

by magic8bot
409 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop
218 stars

Multi-Timeframe Analysis Suite calculates trend direction and momentum conditions across five user-selected timeframes using moving averages, RSI, and Stochastic oscillators. It evaluates moving average slope and oscillator levels to compute trend alignment, m

Indicator v6 Screeners & dashboardsTrend
Updated 3 months ago · None stated GitHub repository of Multi-Timeframe Analysis Suite

KamaFama

by Mastaaa1987
141 stars

KamaFama is an indicator that translates a Freqtrade trading strategy into Pine Script for visualization. It combines Kaufman Adaptive Moving Average (KAMA), MAMA/FAMA calculations derived via Hilbert Transform, Williams %R, and correlation trend filters to ev

Indicator v6 Moving averagesOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of KamaFama

MultiIndicator

by capissimo
114 stars

MultiIndicator combines multiple technical indicators into a single separate pane to save chart space. It calculates and displays market regime detection based on ordinary least squares regression, a Holt exponential smoothing crossover, normalized RSI, ADX, a

Indicator v4 Oscillators & momentumTrend
Updated 1 year ago · None stated GitHub repository of MultiIndicator

Elder Impulse System

by mihakralj
99 stars

Elder Impulse System plots a column series in a separate pane. It compares a 13-period exponential moving average with its previous value and a MACD histogram with its previous value. A rising EMA and rising histogram print 1, a falling EMA and falling histogr

Indicator v5 TrendOscillators & momentum
Updated 4 weeks ago · Apache-2.0 GitHub repository of Elder Impulse System
47 stars

This indicator calculates the Williams Gator Oscillator derived from Bill Williams Alligator lines and plots dual histograms in a separate pane. The upper histogram displays the absolute difference between the Jaw and Teeth moving averages, while the lower his

Indicator v6 Oscillators & momentumMoving averages
Updated 8 months ago · MIT GitHub repository of Williams Gator Oscillator

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers