Indicator · Pine Script v4 · Own pane

Armonia de los MACD

by micayael

A separate-pane indicator that plots a MACD with a simple-average signal line, colored by whether it is rising or falling around zero.

View on GitHub

GitHub stars1on the repository
Pine versionv4older, still runs
Lines of code139
Settings7inputs
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

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

armonia_de_los_macd-bitcoinersla.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
////////////////////////////////////////////////////////////////////////////////

//macd2Timeframe = input(title="Temporalidad MACD secundario", type=input.resolution, defval="0", tooltip="1m -> 5m/5m -> 15m/15m -> 1h/1h -> 4h/4h -> D/D -> S")

fastMA = input(title="Fast moving average", type=input.integer, defval=12, minval=7)
slowMA = input(title="Slow moving average", type=input.integer, defval=26, minval=7)

signalLength = input(title="Signal Length", defval=9, minval=1)

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

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

signal = sma(currMacd, signalLength)

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

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

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

////////////////////////////////////////////////////////////////////////////////
// MACD SECUNDARIO
////////////////////////////////////////////////////////////////////////////////

mutiplier = 0
macd2activated = false

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

fastMA2 = fastMA * mutiplier
slowMA2 = slowMA * mutiplier
signalLength2 = signalLength * mutiplier

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


signal2 = sma(currMacd2, signalLength2)

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

transparency = 50

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

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

// ciclo alcista

macdBullish = currMacd > 0
signalBullish = signal > 0

macd2Bullish = currMacd2 > 0
signal2Bullish = signal2 > 0

macdSignalBullish = macdBullish and signalBullish 
macdSignal2Bullish = macd2Bullish and signal2 > signal2[1]

// ciclo bajista

macdBerish = currMacd < 0
signalBerish = signal < 0

macd2Berish = currMacd2 < 0
signal2Berish = signal2 < 0

macdSignalBerish = macdBerish and signalBerish 
macdSignal2Berish = macd2Berish and signal2Berish

// colores de fondo

rsiSource = input(title="RSI Source", type=input.source, defval=close)
rsiLength = input(title="RSI Length", type=input.integer, defval=14)
rsiOverbought = input(title="RSI Overbought", type=input.integer, defval=80)
rsiOverselling = input(title="RSI Overselling", type=input.integer, defval=20)
rsiValue = rsi(rsiSource, rsiLength)

bgcolor = rsiValue > rsiOverbought ? color.red : 
   rsiValue < rsiOverselling ? color.green : na

bgcolor(color=color.new(bgcolor, 80), title="Sobrecompra o sobreventa")

// Alertas

armoniaAlcistaDetectada = macdSignalBullish and macdSignal2Bullish
armoniaAlcistaHidden = armoniaAlcistaDetectada

if(armoniaAlcistaDetectada and armoniaAlcistaHidden[1])
    armoniaAlcistaDetectada := false


armoniaBajistaDetectada = macdSignalBerish and macdSignal2Berish
armoniaBajistaHidden = armoniaBajistaDetectada

if(armoniaBajistaDetectada and armoniaBajistaHidden[1])
    armoniaBajistaDetectada := false

plotshape(armoniaAlcistaDetectada, title="Inicio de armonía alcista detectada", style=shape.triangleup, color=color.green, location=location.bottom)
plotshape(armoniaBajistaDetectada, title="Inicio de armonía bajista detectada", style=shape.triangledown, color=color.red, location=location.bottom)

alertcondition(armoniaAlcistaDetectada, title="Señal de inicio de armonía alcista detectada", message="Armonía alcista detectada en {{ticker}}\nTemporalidad: {{interval}}")
alertcondition(armoniaBajistaDetectada, title="Señal de inicio de armonía bajista detectada", message="Armonía bajista detectada en {{ticker}}\nTemporalidad: {{interval}}")

Overview

On common timeframes it also plots a second MACD scaled up by a fixed multiplier toward a higher timeframe, drawn as circles. Colors are intended to show when both MACDs agree in direction. Settings change the fast, slow and signal lengths, and RSI inputs are defined. Code comments and labels are partly 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
Fast moving averageint12fastMA
Slow moving averageint26slowMA
Signal Lengthint9signalLength
RSI SourcesourceclosersiSource
RSI Lengthint14rsiLength
RSI Overboughtint80rsiOverbought
RSI Oversellingint20rsiOverselling
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