//@version=3
study("Kozlod - Pivot Reversal Strategy Alerts", overlay=true)
//
// author: Kozlod
// date: 2018-03-11
//
////////////
// INPUTS //
////////////
leftBars = input(4)
rightBars = input(2)
/////////////
// SIGNALS //
/////////////
swh = pivothigh(leftBars, rightBars)
swl = pivotlow(leftBars, rightBars)
swh_cond = not na(swh)
hprice = 0.0
hprice := swh_cond ? swh : hprice[1]
le = false
le := swh_cond ? true : (le[1] and high > hprice ? false : le[1])
swl_cond = not na(swl)
lprice = 0.0
lprice := swl_cond ? swl : lprice[1]
se = false
se := swl_cond ? true : (se[1] and low < lprice ? false : se[1])
// Filter out signals if oposite signal is also on
se_filt = se and not le
le_filt = le and not se
// Filter out consecutive signals
prev = 0
prev := se_filt ? 1 : le_filt ? -1 : prev[1]
se_final = se_filt and prev[1] == -1
le_final = le_filt and prev[1] == 1
// Plot Signals
plotshape(se_final, color = red, text = "se")
plotshape(le_final, color = green, text = "le")
// Create cistom alserts
alertcondition(se_final, "se", "se")
alertcondition(le_final, "le", "le")