Double MACD Pattern 1.0
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © egghen

//@version=5
indicator('Double MACD Pattern 1.0', shorttitle='D-MACD-P 1.0')

// MACD Settings
slowLength_1 = input(title='MACD 1 Fast Length', defval=12, group="MACD 1")
fastLength_1 = input(title='MACD 1 Slow Length', defval=26, group="MACD 1")
signalLength_1 = input(title='MACD 1 Signal Length', defval=9, group="MACD 1")
fastLength_2 = input(title='MACD 2 Fast Length', defval=12, group="MACD 2")
slowLength_2 = input(title='MACD 2 Slow Length', defval=26, group="MACD 2")
signalLength_2 = input(title='MACD 2 Signal Length', defval=9, group="MACD 2")

// Define Calculation
macdLine_1 = ta.ema(hl2, fastLength_1) - ta.ema(hl2, slowLength_1)
macdLine_2 = ta.ema(hl2, fastLength_2) - ta.ema(hl2, slowLength_2)
signalLine_1 = ta.ema(macdLine_1, signalLength_1)
signalLine_2 = ta.ema(macdLine_2, signalLength_2)

// Calculate MACD Histograms
histogram_1 = macdLine_1 - signalLine_1
histogram_2 = macdLine_2 - signalLine_2

// Plot MACD Line
plot(macdLine_1, color=color.new(#6a71ed, 0), linewidth=2, title='MACD Line 1')
plot(signalLine_1, color=color.rgb(235, 96, 68), title='Signal Line 1')
plot(macdLine_2, color=color.new(#b3d0e7, 40), linewidth=2, title='MACD Line 2')
plot(signalLine_2, color=color.rgb(117, 243, 33), title='Signal Line 2')

// Plot Histograms
plot(histogram_1, color=color.new(#f41d1d, 0), style=plot.style_histogram, title='Histogram 1')
plot(histogram_2, color=color.new(#0788f1, 0), style=plot.style_histogram, title='Histogram 2')

hline(0, color=#787B86, linestyle=hline.style_dashed, title="Trend Line")

// Alert on MACD Crossover and Crossunder
long_signal = ta.crossunder(macdLine_1, signalLine_1) and ta.crossover(macdLine_2, signalLine_2) and ta.crossover(histogram_1, histogram_2)
short_signal = ta.crossover(macdLine_1, signalLine_1) and ta.crossunder(macdLine_2, signalLine_2) and ta.crossunder(histogram_1, histogram_2)
potential_long = ta.crossover(macdLine_2, signalLine_2) and ta.crossunder(macdLine_1, signalLine_1)
potential_short = ta.crossunder(macdLine_2, signalLine_2) and ta.crossover(macdLine_1, signalLine_1)
up_trend = ta.crossover(macdLine_2, macdLine_1)
down_trend = ta.crossover(macdLine_1, macdLine_2)

// Send an Alert
if long_signal
    alert('D-MACD+p 1.1 - Long Signal.')
if short_signal
    alert('D-MACD+p 1.1 - Short Signal.')
if up_trend
    alert('D-MACD+p 1.1 - Up Trend Signal.')
if down_trend
    alert('D-MACD+p 1.1 - Down Trend Signal.')
if potential_long
    alert('D-MACD+p 1.1 - Potential Long Signal.')
if potential_short
    alert('D-MACD+p 1.1 - Potential Short Signal.')
//

// end code