Indicator · Pine Script v6 · Own pane

MACD + CMF MTF Signals

by eddiebelaval· code credited to Fenris74

This indicator calculates Multi-Timeframe Moving Average Convergence Divergence (MACD) and Chaikin Money Flow (CMF) combined in a separate pane.

View on GitHub

Repaints

GitHub stars7on the repository
Pine versionv6current
Lines of code125
Settings9inputs
LicenceNone statedfile: MPL-2.0
Last update3 months ago24 Jul 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

125 lines of Pine Script v6 from pinescript/moving_averages/macd-cmf-mtf-signals.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

macd-cmf-mtf-signals.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Fenris74
//V0.3


//@version=6
indicator(
     title      = "MACD + CMF MTF Signals",
     shorttitle = "MACD+CMF",
     overlay    = false,
     max_lines_count = 500,
     max_labels_count = 500
)

//──────────────────────
// Inputs
//──────────────────────
group_macd = "MACD Settings"
fastLen   = input.int(12,  "Fast Length",   minval=1, group=group_macd)
slowLen   = input.int(26,  "Slow Length",   minval=1, group=group_macd)
sigLen    = input.int(9,   "Signal Length", minval=1, group=group_macd)
tfMACD    = input.timeframe("", "MACD Timeframe (empty = chart)", group=group_macd)

group_cmf = "CMF Settings"
cmfLen    = input.int(21,  "CMF Length",    minval=1, group=group_cmf)
tfCMF     = input.timeframe("", "CMF Timeframe (empty = chart)", group=group_cmf)

group_vis = "Visual Settings"
showHist  = input.bool(true,  "Show MACD Histogram",         group=group_vis)
showCMF   = input.bool(true,  "Show CMF Line (auto-scaled)", group=group_vis)
showMarks = input.bool(true,  "Show Buy/Sell Markers",       group=group_vis)

//──────────────────────
// MACD (MTF)
//──────────────────────
macdTf        = tfMACD == "" ? timeframe.period : tfMACD
srcClose_macd = request.security(syminfo.tickerid, macdTf, close)

fastMA = ta.ema(srcClose_macd, fastLen)
slowMA = ta.ema(srcClose_macd, slowLen)
macd   = fastMA - slowMA
signal = ta.ema(macd, sigLen)
hist   = macd - signal

//──────────────────────
// CMF (MTF)
//──────────────────────
cmfTf = tfCMF == "" ? timeframe.period : tfCMF

h_htf = request.security(syminfo.tickerid, cmfTf, high)
l_htf = request.security(syminfo.tickerid, cmfTf, low)
c_htf = request.security(syminfo.tickerid, cmfTf, close)
v_htf = request.security(syminfo.tickerid, cmfTf, volume)

priceRange = h_htf - l_htf
mfm        = priceRange == 0.0 ? 0.0 : ((c_htf - l_htf) - (h_htf - c_htf)) / priceRange
mfv        = mfm * v_htf

cmf_num = ta.sma(mfv,   cmfLen)
cmf_den = ta.sma(v_htf, cmfLen)
cmf_raw = cmf_den == 0.0 ? 0.0 : cmf_num / cmf_den

//──────────────────────
// Auto-Scaling für CMF
//──────────────────────
macdHigh  = ta.highest(macd, 200)
macdLow   = ta.lowest(macd, 200)
macdRange = math.max(math.abs(macdHigh), math.abs(macdLow))

cmfHigh   = ta.highest(cmf_raw, 200)
cmfLow    = ta.lowest(cmf_raw, 200)
cmfRange  = math.max(math.abs(cmfHigh), math.abs(cmfLow))

cmfRangeSafe = cmfRange == 0.0 ? 0.0001 : cmfRange
autoScale    = macdRange / cmfRangeSafe
cmf_scaled   = cmf_raw * autoScale

//──────────────────────
// Buy/Sell Logic
//──────────────────────
bullCross = ta.crossover(macd, signal)
bearCross = ta.crossunder(macd, signal)

buyCond  = bullCross and cmf_raw > 0
sellCond = bearCross and cmf_raw < 0

//──────────────────────
// MACD Panel
//──────────────────────
plot(macd,   "MACD",   color=color.teal,   linewidth=2)
plot(signal, "Signal", color=color.orange, linewidth=2)

// Histogramm mit Grau-Logik
histColor =
     hist >= 0 and hist > hist[1] ? color.new(color.green, 0) :
     hist >= 0 and hist < hist[1] ? color.new(color.gray, 20) :
     hist < 0  and hist > hist[1] ? color.new(color.red,   0) :
     color.new(color.gray, 20)

plot(
     showHist ? hist : na,
     "Histogram",
     style = plot.style_columns,
     color = histColor
)

// CMF sichtbar (auto-scaled)
plot(
     showCMF ? cmf_scaled : na,
     "CMF (auto-scaled)",
     color=color.purple,
     linewidth=2
)

//──────────────────────
// Buy/Sell Markers
//──────────────────────
plotshape(showMarks and buyCond,  title="Buy",  style=shape.triangleup,   location=location.bottom, color=color.lime, size=size.tiny)
plotshape(showMarks and sellCond, title="Sell", style=shape.triangledown, location=location.top,    color=color.red,  size=size.tiny)

//──────────────────────
// Alerts
//──────────────────────
alertcondition(buyCond,  title="Buy Signal",  message="MACD+CMF MTF Buy Signal")
alertcondition(sellCond, title="Sell Signal", message="MACD+CMF MTF Sell Signal")

Overview

MACD + CMF MTF Signals plots the MACD, signal line, histogram, and an auto-scaled CMF line. Buy markers trigger when a bullish MACD crossover occurs while CMF is positive, while sell markers display on a bearish MACD crossunder with negative CMF. Users can independently adjust periods and timeframes for MACD and CMF, as well as toggle display elements. Multi-timeframe settings may repaint on open higher-timeframe bars.

Details

Published by

eddiebelaval on GitHub

Code credit

Fenris74, as written in the script's header

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Oscillators & momentum, Volume, Moving averages

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)

Settings

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

SettingTypeDefaultVariable
Fast Lengthint12fastLen
Slow Lengthint26slowLen
Signal Lengthint9sigLen
MACD Timeframe (empty = chart)timeframetfMACD
CMF Lengthint21cmfLen
CMF Timeframe (empty = chart)timeframetfCMF
Show MACD HistogrambooltrueshowHist
Show CMF Line (auto-scaled)booltrueshowCMF
Show Buy/Sell MarkersbooltrueshowMarks
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

Aggregate Signal (v.2)

by capissimo
114 stars

Aggregate Signal (v.2) is an oscillator indicator that combines multiple technical factors into a single composite score. It scales OHLCV data using minimax normalization and evaluates indicators such as MACD, RSI, Stochastic, CCI, Momentum, On-Balance Volume,

Indicator v4 Oscillators & momentumMoving averages Repaints
Updated 1 year ago · None stated GitHub repository of Aggregate Signal (v.2)

Volume-Weighted MACD

by mihakralj
99 stars

This indicator plots a volume-weighted MACD in a separate pane. It subtracts a slow volume-weighted moving average of close from a faster one, then smooths that line with an exponential moving average to form the signal. A column histogram shows the gap betwee

Indicator v5 Oscillators & momentumMoving averages
Updated 4 weeks ago · Apache-2.0 GitHub repository of Volume-Weighted MACD

PPO ATR Bands

by cryptorife
75 stars

PPO ATR Bands plots a percentage price oscillator in a separate pane. It compares a Hull average of typical price with a volume-weighted exponential average of Parabolic SAR, then scales three true-range bands around the slow average into matching oscillator l

Indicator v4 Oscillators & momentumMoving averages
Updated 3 years ago · GPL-3.0 GitHub repository of PPO ATR Bands

RSI-VWMA

by Zettt
43 stars

This indicator calculates the Relative Strength Index using a volume-weighted moving average of the closing price as its source. It plots the resulting oscillator in a separate pane alongside configurable overbought and oversold threshold lines. The plot line

Indicator v4 Oscillators & momentumMoving averages
Updated 1 year ago · None stated GitHub repository of RSI-VWMA

Trap Shorts - Hamza Naveed

by ProfHamzaNaveed
43 stars

This indicator tracks and visualizes cryptocurrency net positioning across multiple derivative exchanges, including Binance, BitMEX, and Kraken. It calculates aggregated net longs, net shorts, net delta, and ratio metrics, or an optional Position RSI, renderin

Indicator v5 VolumeOscillators & momentum
Updated 9 months ago · None stated GitHub repository of Trap Shorts - Hamza Naveed

NFI v6

by koradiyakaushal
12 stars

This Pine v4 study ports early NostalgiaForInfinity V6 conditions onto the price chart. It computes two Bollinger setups, several EMAs and SMAs, RSI, MFI, a percent SMA spread labeled EWO, a 14-period choppiness value, and short and longer volume medians. Fixe

Indicator v4 Moving averagesVolatility & bands
Updated 5 years ago · MIT GitHub repository of NFI v6

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