Indicator · Pine Script v4 · Own pane

Armonia de los MACD (v2)

by micayael

A separate-pane indicator that plots a slow MACD, 21 and 200 periods by default, against a long simple-average signal line, colored green or red by which is higher.

View on GitHub

GitHub stars1on the repository
Pine versionv4older, still runs
Lines of code164
Settings10inputs
LicenceNone statedfile: MPL-2.0
Last update4 years ago16 Feb 2022

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

164 lines of Pine Script v4 from armonia_de_los_macd.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

armonia_de_los_macd.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © micayael

//@version=4
study(title="Armonía de los MACD", shorttitle="Armonía de los MACD")

////////////////////////////////////////////////////////////////////////////////
// INPUTS
////////////////////////////////////////////////////////////////////////////////

// Inputs para el MACD Principal
// ----------------------------------------------------------------------------

showMacd = input(title="Mostrar MACD Principal", type=input.bool, defval=true)

fastMA = input(title="Media Móvil Rápida", type=input.integer, defval=21, minval=7)
slowMA = input(title="Media Móvil Lenta", type=input.integer, defval=200, minval=7)
signalMACD = input(title="Longitud de la Señal del MACD", type=input.integer, defval=9, minval=7)

signalLength = input(title="Longitud de la Señal", defval=120, minval=1)

// Inputs para el MACD de la temporalidad superior
// ----------------------------------------------------------------------------

showMacd2 = input(title="Mostrar MACD de Temporalidad Superior", type=input.bool, defval=true, tooltip="Solo para las temporalidades: 1m -> 5m/5m -> 15m/15m -> 1h/1h -> 4h/4h -> D/D -> S")

fastMA2 = input(title="Media Móvil Rápida - MACD Superior", type=input.integer, defval=12, minval=7)
slowMA2 = input(title="Media Móvil Lenta - MACD Superior", type=input.integer, defval=21, minval=7)
signalMACD2 = input(title="Longitud de la Señal del MACD Superior", type=input.integer, defval=9, minval=7)

signalLength2 = input(title="Longitud de la Señal - Temporalidad Superior", defval=60, minval=1)

////////////////////////////////////////////////////////////////////////////////
// MACD PRINCIPAL
////////////////////////////////////////////////////////////////////////////////

[currMacd,_,_] = macd(close[0], fastMA, slowMA, signalMACD)
[prevMacd,_,_] = macd(close[1], fastMA, slowMA, signalMACD)

signal = sma(currMacd, signalLength)

macdColor = currMacd > signal ? color.lime : 
   currMacd < signal ? color.red : color.yellow

plot(0, title="Punto 0", linewidth=1, color=color.white, style=plot.style_line)

plot(showMacd ? currMacd : na, title="MACD Principal", style=plot.style_line, color=macdColor, linewidth=2)
plot(showMacd ? signal : na, title="Señal Principal", color=color.blue, linewidth=2)

////////////////////////////////////////////////////////////////////////////////
// MACD DE TEMPORALIDAD SUPERIOR
////////////////////////////////////////////////////////////////////////////////

calcularTemporalidadSuperior() =>
    temporalidadSoportada = false
    mutiplier = 0

    if timeframe.period == "1" //1m > 5m
        mutiplier := 5
        temporalidadSoportada := true
    else if timeframe.period == "5" //5m > 15m
        mutiplier := 3
        temporalidadSoportada := true
    else if timeframe.period == "15" //15m > 1h
        mutiplier := 4
        temporalidadSoportada := true
    else if timeframe.period == "60" //1h > 4h
        mutiplier := 4
        temporalidadSoportada := true
    else if timeframe.period == "240" //4h > D
        mutiplier := 6
        temporalidadSoportada := true
    else if timeframe.period == "D" // D > S
        mutiplier := 7
        temporalidadSoportada := true
    [mutiplier, temporalidadSoportada]

[mutiplier, temporalidadSoportada] = calcularTemporalidadSuperior()

fastMA2 := fastMA2 * mutiplier
slowMA2 := slowMA2 * mutiplier
signalLength2 := signalLength2 * mutiplier

[currMacd2,_,_] = macd(close[0], fastMA2, slowMA2, signalMACD2)
[prevMacd2,_,_] = macd(close[1], fastMA2, slowMA2, signalMACD2)


signal2 = sma(currMacd2, signalLength2)

macd2Color = currMacd2 > signal2 ? color.lime : 
   currMacd2 < signal2 ? color.red : color.yellow

transparency = 50

plot(showMacd2 and temporalidadSoportada ? currMacd2 : na, title="MACD Secundario", style=plot.style_circles, color=color.new(macd2Color, transparency), linewidth=2)
plot(showMacd2 and temporalidadSoportada ? signal2 : na, title="Señal Secundaria", style=plot.style_circles, color=color.new(color.blue, transparency), linewidth=2)

////////////////////////////////////////////////////////////////////////////////
// ARMONIA - COLORES
////////////////////////////////////////////////////////////////////////////////

// ciclo alcista
// ----------------------------------------------------------------------------

macdBullish = currMacd > signal
macd2Bullish = currMacd2 > signal2

longAgresivo = not macdBullish[1] and macdBullish and signal < 0
longConservador = not macdBullish[1] and macdBullish and signal > 0

longAgresivoHidden = longAgresivo
longConservadorHidden = longConservador

if(longAgresivo and longAgresivoHidden[1])
    longAgresivo := false

if(longConservador and longConservadorHidden[1])
    longConservador := false

// ciclo bajista
// ----------------------------------------------------------------------------

macdBerish = currMacd < signal
macd2Berish = currMacd2 < signal2

shortAgresivo = not macdBerish[1] and macdBerish and signal > 0
shortConservador = not macdBerish[1] and macdBerish and signal < 0

shortAgresivoHidden = shortAgresivo
shortConservadorHidden = shortConservador

if(shortAgresivo and shortAgresivoHidden[1])
    shortAgresivo := false

if(shortConservador and shortConservadorHidden[1])
    shortConservador := false

// Señales
// ----------------------------------------------------------------------------

plotshape(longAgresivo, title="Long Agresivo", style=shape.labelup, color=color.green, location=location.bottom, text="Long+", textcolor=color.white)
plotshape(longConservador, title="Long Conservador", style=shape.labelup, color=color.yellow, location=location.bottom, text="Long-", textcolor=color.black)

plotshape(shortAgresivo, title="Short Agresivo", style=shape.labeldown, color=color.red, location=location.top, text="Short+", textcolor=color.white)
plotshape(shortConservador, title="Short Conservador", style=shape.labeldown, color=color.yellow, location=location.top, text="Short-", textcolor=color.black)

// colores de fondo para armonía entre los MACD

bgcolorArmonia = macdBullish and macd2Bullish ? color.green : 
   macdBerish and macd2Berish ? color.red : na

bgcolor(color=color.new(bgcolorArmonia, 80), title="Sincronización del MACD")

// Alertas
// ----------------------------------------------------------------------------

alertcondition(longAgresivo, title="Señal de Long Agresivo", message="Señal de Long Agresivo detectado en {{ticker}}\nTemporalidad: {{interval}}")
alertcondition(longConservador, title="Señal de Long Conservador", message="Señal de Long Conservador detectado en {{ticker}}\nTemporalidad: {{interval}}")

alertcondition(shortAgresivo, title="Señal de Short Agresivo", message="Señal de Short Agresivo detectado en {{ticker}}\nTemporalidad: {{interval}}")
alertcondition(shortConservador, title="Señal de Short Conservador", message="Señal de Short Conservador detectado en {{ticker}}\nTemporalidad: {{interval}}")

alertcondition(longAgresivo or longConservador, title="Señal de Long Agresivo o Conservador", message="Long Agresivo o Conservador detectado en {{ticker}}\nTemporalidad: {{interval}}")
alertcondition(shortAgresivo or shortConservador, title="Señal de Short Agresivo o Conservador", message="Short Agresivo o Conservador detectado en {{ticker}}\nTemporalidad: {{interval}}")

Overview

A second MACD can be shown, with its lengths multiplied by a factor chosen for the chart timeframe to stand in for the next higher timeframe, such as five times on a one-minute chart. Each MACD can be switched off, and all lengths are editable. Settings are labelled in Spanish.

Details

Published by

micayael on GitHub

Type

Indicator, Pine Script v4

Draws

Separate pane below the chart

Category

Oscillators & momentum, Trend

Markets

Crypto

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
Mostrar MACD PrincipalbooltrueshowMacd
Media Móvil Rápidaint21fastMA
Media Móvil Lentaint200slowMA
Longitud de la Señal del MACDint9signalMACD
Longitud de la Señalint120signalLength
Mostrar MACD de Temporalidad SuperiorbooltrueshowMacd2
Media Móvil Rápida - MACD Superiorint12fastMA2
Media Móvil Lenta - MACD Superiorint21slowMA2
Longitud de la Señal del MACD Superiorint9signalMACD2
Longitud de la Señal - Temporalidad Superiorint60signalLength2
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

Schaff Trend Cycle

by everget
948 stars

This indicator plots the Schaff Trend Cycle in a separate pane. It subtracts a slow exponential moving average from a fast one, applies a stochastic cycle twice, and smooths each result to form a 0–100 oscillator. Line color follows the slope, or the upper and

Indicator v4 Oscillators & momentumTrend
Updated 11 days ago · GPL-3.0 GitHub repository of Schaff Trend Cycle

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

[RS]Standardized Trend Map

by ricardosantos79
261 stars

Standardized Trend Map calculates series momentum relative to active price range across 40 distinct lookback periods ranging from 2 to 80 bars on an exponential moving average source. Each standardized calculation rounds to an integer values of -1, 0, or 1 to

Indicator v4 TrendOscillators & momentum
Updated 4 years ago · None stated GitHub repository of [RS]Standardized Trend Map

ADX Histogram

by harryguiacorn
219 stars

This indicator calculates and displays the Average Directional Index (ADX) as a column histogram in a separate pane. It evaluates market trend strength by calculating directional movement metrics based on specified smoothing and DI length inputs. When the ADX

Indicator v5 TrendOscillators & momentum
Updated 1 year ago · None stated GitHub repository of ADX Histogram
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

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