Binary Combo
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ZacVaughn

//@version=4
study("𝐁𝐈𝐍𝐀𝐑𝐘 𝐂𝐎𝐌𝐁𝐎")


//WAVETREND CROSS▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼

hline(110, color=color.new(#ffffff, 75))
hline(-90, color=color.new(#ffffff, 75))

n1 = 9
n2 = 12
ap = hlc3 
esa = ema(ap, n1)
d1 = ema(abs(ap - esa), n1)
ci = (ap - esa) / (0.015 * d1)
tci = ema(ci, n2)
hline = 0
wt1 = tci
wt2 = sma(wt1, 4)

wt1color = wt1 > 0 ? #00bcd4 : #e91e63
wtcrossuppre = wt1 > wt2 and wt1[1] < wt2[1] and wt2 < -10
wtcrossdownpre = wt1 < wt2 and wt1[1] > wt2[1] and wt2 > 10
wtcrossup = wtcrossuppre or wtcrossuppre[1] or wtcrossuppre[2]
wtcrossdown = wtcrossdownpre or wtcrossdownpre[1] or wtcrossdownpre[2]

plot(wt1, style=plot.style_areabr, color=wt1color)
plot(wt2, style=plot.style_areabr, color=color.new(#5d606b, 50))
plot(wt2, color=color.new(#000000, 50), linewidth=2)
plot(wtcrossuppre ? wt2 : na, title="Cross Up Circles", color=#00bcd4, style=plot.style_circles, linewidth=3)
plot(wtcrossdownpre ? wt2 : na, title="Cross down Circles", color=#e91e63, style=plot.style_circles, linewidth=3)


//STOCH DIVERGENCE▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼

periodK14 = 14
smoothK14 = 3
periodD14 = 3
k14 = sma(stoch(close, high, low, periodK14), smoothK14)
d14 = sma(k14, periodD14)
plot(k14, title="%K", linewidth=2, color=#ffeb3b)
plot(d14, title="%D", linewidth=1, color=#ffffff)
h0 = hline(80, "Upper Band", linestyle=hline.style_solid, color=color.new(#787B86, 50))
h1 = hline(20, "Lower Band", linestyle=hline.style_solid, color=color.new(#787B86, 50))
fill(h0, h1, color=color.new(#00bcd4, 90), title="Background")

//Divergence
lbR14 = 2
lbL14 = 6
rangeUpper14 = 60
rangeLower14 = 5
plotBull14 = true
plotHiddenBull14 = false
plotBear14 = true
plotHiddenBear14 = false

bearColor14 = #e91e63
bullColor14 = #00bcd4
hiddenBullColor14 = #00bcd4
hiddenBearColor14 = #e91e63
textColor14 = color.white
noneColor14 = color.new(color.white, 100)

osc14 = k14

plFound14 = na(pivotlow(osc14, lbL14, lbR14)) ? false : true
phFound14 = na(pivothigh(osc14, lbL14, lbR14)) ? false : true

_inRange14(cond) =>
    bars14 = barssince(cond == true)
    rangeLower14 <= bars14 and bars14 <= rangeUpper14

//Regular Bullish

//Osc: Higher Low
oscHL14 = osc14[lbR14] > valuewhen(plFound14, osc14[lbR14], 1) and _inRange14(plFound14[1])

//Price: Lower Low
priceLL14 = low[lbR14] < valuewhen(plFound14, low[lbR14], 1)

bullCond14 = plotBull14 and priceLL14 and oscHL14 and plFound14
plot(plFound14 ? osc14[lbR14] : na, offset=-lbR14, title="Regular Bullish", linewidth=2, color=(bullCond14 ? bullColor14 : noneColor14))
plotshape(bullCond14 ? osc14[lbR14] : na, offset=-lbR14, title="Regular Bullish Label", text="𝐁𝐔𝐋𝐋", style=shape.labelup, location=location.absolute, color=bullColor14, textcolor=textColor14)

//Hidden Bullish

//Osc: Lower Low
oscLL14 = osc14[lbR14] < valuewhen(plFound14, osc14[lbR14], 1) and _inRange14(plFound14[1])

//Price: Higher Low
priceHL14 = low[lbR14] > valuewhen(plFound14, low[lbR14], 1)

hiddenBullCond14 = plotHiddenBull14 and priceHL14 and oscLL14 and plFound14
plot(plFound14 ? osc14[lbR14] : na, offset=-lbR14, title="Hidden Bullish", linewidth=2, color=(hiddenBullCond14 ? hiddenBullColor14 : noneColor14))
plotshape(hiddenBullCond14 ? osc14[lbR14] : na, offset=-lbR14, title="Hidden Bullish Label", text=" H Bull ", style=shape.labelup, location=location.absolute, color=bullColor14, textcolor=textColor14)

//Regular Bearish

//Osc: Lower High
oscLH14 = osc14[lbR14] < valuewhen(phFound14, osc14[lbR14], 1) and _inRange14(phFound14[1])

//Price: Higher High
priceHH14 = high[lbR14] > valuewhen(phFound14, high[lbR14], 1)

bearCond14 = plotBear14 and priceHH14 and oscLH14 and phFound14
plot(phFound14 ? osc14[lbR14] : na, offset=-lbR14, title="Regular Bearish", linewidth=2, color=(bearCond14 ? bearColor14 : noneColor14))
plotshape(bearCond14 ? osc14[lbR14] : na, offset=-lbR14, title="Regular Bearish Label", text="𝐁𝐄𝐀𝐑", style=shape.labeldown, location=location.absolute, color=bearColor14, textcolor=textColor14)
	 
//Hidden Bearish

//Osc: Higher High
oscHH14 = osc14[lbR14] > valuewhen(phFound14, osc14[lbR14], 1) and _inRange14(phFound14[1])

//Price: Lower High
priceLH14 = high[lbR14] < valuewhen(phFound14, high[lbR14], 1)

hiddenBearCond14 = plotHiddenBear14 and priceLH14 and oscHH14 and phFound14
plot(phFound14 ? osc14[lbR14] : na, offset=-lbR14, title="Hidden Bearish", linewidth=2, color=(hiddenBearCond14 ? hiddenBearColor14 : noneColor14))
plotshape(hiddenBearCond14 ? osc14[lbR14] : na, offset=-lbR14, title="Hidden Bearish Label", text=" H Bear ", style=shape.labeldown, location=location.absolute, color=bearColor14, textcolor=textColor14)

bulldiv = bullCond14 or bullCond14[1] or bullCond14[2]
beardiv = bearCond14 or bearCond14[1] or bearCond14[2]


//PLOT STARS▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼

plot(wtcrossup and bulldiv ? -90 : na, style=plot.style_circles, color=color.new(#ffeb3b, 50), linewidth=6)
plot(wtcrossup and bulldiv ? -90 : na, style=plot.style_circles, color=color.new(#ffffff, 0), linewidth=2)
plot(wtcrossdown and beardiv ? 110 : na, style=plot.style_circles, color=color.new(#ffeb3b, 50), linewidth=6)
plot(wtcrossdown and beardiv ? 110 : na, style=plot.style_circles, color=color.new(#ffffff, 0), linewidth=2)
