Indicator · Pine Script v5 · Own pane

MACD

by trsdn

This indicator implements a standard Moving Average Convergence Divergence oscillator plotted in a separate pane.

View on GitHub

GitHub stars6on the repository
Pine versionv5runs as is
Lines of code25
Settings3inputs
LicenceMIT
Last update5 days ago23 Oct 2026

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

25 lines of Pine Script v5 from strategies/ai-macd.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

ai-macd.pine
// Source: TradingView Built-in Indicator (MACD)
// Attribution: Standard MACD implementation matching TradingView's built-in indicator
// Used as input for AI-powered strategy conversion

//@version=5
indicator("MACD", overlay=false)

fastLength = input.int(12, "Fast Length", minval=1)
slowLength = input.int(26, "Slow Length", minval=1)
signalLength = input.int(9, "Signal Smoothing", minval=1)

fastMA = ta.ema(close, fastLength)
slowMA = ta.ema(close, slowLength)
macdLine = fastMA - slowMA
signalLine = ta.ema(macdLine, signalLength)
histogram = macdLine - signalLine

plot(macdLine, color=color.blue, title="MACD")
plot(signalLine, color=color.orange, title="Signal")
plot(histogram, color=histogram >= 0 ? color.green : color.red, style=plot.style_histogram, title="Histogram")

Additional instructions:
- This is a standard MACD crossover strategy. Enter when MACD crosses above signal, exit when it crosses below.
- Use ta.crossover() and ta.crossunder() for clean signal detection.
- The strategy enters/exits on the next candle open after the condition is met.

Overview

MACD calculates fast and slow exponential moving averages of the closing price, derives the MACD line from their difference, and smooths it to create a signal line. A colored histogram displays the difference between the MACD and signal lines. Users can configure the fast length, slow length, and signal smoothing periods. It serves as a base indicator template for automated strategy conversion.

Details

Published by

trsdn on GitHub

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Oscillators & momentum, Moving averages

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.

Topics

ai-scrumalgorithmic-tradingbacktestingbitcoinbollinger-bandscryptopine-scriptpythonquantitative-financestrategy

Settings

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

SettingTypeDefaultVariable
Fast Lengthint12fastLength
Slow Lengthint26slowLength
Signal Smoothingint9signalLength
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

948 stars

The Derivative Oscillator calculates a double-exponentially smoothed Relative Strength Index (RSI) and subtracts its Simple Moving Average (SMA) to form the main oscillator line. A secondary signal line is plotted using an SMA of the main oscillator values. Th

Indicator v4 Oscillators & momentumMoving averages
Updated 10 days ago · GPL-3.0 GitHub repository of Derivative Oscillator

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

MACD

by Alorse
330 stars

This indicator calculates and plots the standard Moving Average Convergence Divergence oscillator in a separate pane. It computes the difference between a fast and slow moving average, derives a signal line through smoothing, and plots a histogram representing

Indicator v4 Oscillators & momentumMoving averages
Updated 2 months ago · None stated GitHub repository of MACD

MACD-V

by harryguiacorn
219 stars

MACD-V is a volatility-normalized momentum indicator based on research by Alex Spiroglou. It calculates the standard MACD histogram and normalizes it by dividing by the Average True Range (ATR). Plotted in a separate pane as a colored histogram, it includes us

Indicator v5 Oscillators & momentumVolatility & bands
Updated 1 year ago · None stated GitHub repository of MACD-V
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

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