Alligator: Three signals confirmation with Alerts
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HerschelleGirnari

//@version=5
indicator("Alligator: Three signals confirmation with Alerts", shorttitle="HersG Alli alerts", overlay=true)
//  >>>>>>>>    Inputs

AlliTooltips = "Numbers are Fibonacci numbers. Offset will shift plot data right or left to given number of bars. Min = -4 to Max = 4."

src = input.source(close, title = "Source Data", group = "Moving Average")
MAtype = input.string("EMA", title = "Type", options = ["SMA", "EMA"], group = "Moving Average" )

ALips = input.int(5, title = "Lips", options = [5,8,13,21,34], tooltip = AlliTooltips, inline = "LIPS", group = "Alligator")
AlipsOffset = input.int(3, title = "Offset", minval = -4, maxval = 4, step = 1, tooltip = AlliTooltips, inline = "LIPS", group = "Alligator")

ATeeth = input.int(13, title = "Teeth", options = [8,13,21,34,55], tooltip = AlliTooltips, inline = "TEETH", group = "Alligator")
AteethOffset = input.int(2, title = "Offset", minval = -4, maxval = 4, step = 1, tooltip = AlliTooltips, inline = "TEETH", group = "Alligator")

AJaws = input.int(21, title = "Jaws", options = [21,34,55,89,144], tooltip = AlliTooltips, inline = "JAWS", group = "Alligator")
AjawsOffset = input.int(0, title = "Offset", minval = -4, maxval = 4, step = 1, tooltip = AlliTooltips, inline = "JAWS", group = "Alligator")


//  >>>>>>  Calculation

float AlliLips = 0.0
float AlliTeeth = 0.0
float AlliJaws = 0.0


if MAtype == "SMA"
    AlliLips := ta.sma(src, ALips)
    AlliTeeth := ta.sma(src, ATeeth)
    AlliJaws := ta.sma(src, AJaws)
else
    AlliLips := ta.ema(src, ALips)
    AlliTeeth := ta.ema(src, ATeeth)
    AlliJaws := ta.ema(src, AJaws)

UpMomentum = false
DownMomentum = false
UpCounter = 0
DownCounter = 0

if barstate.isconfirmed

    UpMomentum := hl2 > AlliLips and AlliJaws and AlliTeeth 
    DownMomentum := hl2 < AlliJaws and AlliLips and AlliTeeth

    for i = 0 to 2
        if UpMomentum[i] and (UpMomentum[i] != DownMomentum[i])
            UpCounter := UpCounter + 1
        else
            UpCounter := 0

    for i = 0 to 2
        if DownMomentum[i] and (DownMomentum[i] != UpMomentum[i])
            DownCounter := DownCounter + 1
        else
            DownCounter := 0



// >>>>>>>>>>>   Display

plot(AlliLips, title = "Lips", color = color.green, offset = AlipsOffset)
plot(AlliTeeth, title = "Teeth", color = color.red, offset = AlipsOffset)
plot(AlliJaws, title = "Jaws", color = color.blue, linewidth = 2, offset = AlipsOffset)

plotshape(UpCounter == 3, title = "Up Momentum", style = shape.cross, location = location.bottom, color = color.green, size = size.small)

plotshape(DownCounter == 3, title = "Down Momentum", style = shape.cross, location = location.top, color = color.red, size = size.small)

//   >>>>>>>>>>>  Alerts

if UpCounter == 3
    alert(message = "Up Momentum", freq = alert.freq_once_per_bar_close)
else if DownCounter == 3
    alert(message = "Down Momentum", freq = alert.freq_once_per_bar_close)
else
    na
