The script highlights "Fuller's pins" and generates alerts when these bars are appearing
study("YK Fuller Bars", overlay=true) pTail = input(title="Tail (default 45), %", type=integer, defval=45, minval=0, maxval=100) tail = pTail * 0.01 tail1 = 1 - tail ema1Value = input(title="EMA (default 8)", type=integer, defval=8, minval=1) ema2Value = input(title="EMA (default 21)", type=integer, defval=21, minval=1) ema1 = ema(close, ema1Value) ema2 = ema(close, ema2Value) height = high - low bodyHeight = abs(open - close) fakeHighUp = high - close fakeLowUp = open - low pinHeightUp = height - min(fakeHighUp, fakeLowUp) getPinBarUp(ema1, ema2) => open < close and ((fakeHighUp * 2 < fakeLowUp and bodyHeight > fakeHighUp and ema1 >= low and close > ema1 and open > ema1 and close > ema2 and open > ema2 and open > (close - pinHeightUp * tail1) and close > (high - pinHeightUp * tail1)) or (fakeHighUp > fakeLowUp * 2 and bodyHeight > fakeLowUp and high >= ema1 and close < ema1 and close < ema2 and open < (high - pinHeightUp * tail) and close < (high - pinHeightUp * tail))) ? true : false pinBarUp1 = getPinBarUp(ema1, ema2) pinBarUp = pinBarUp1 ? pinBarUp1 : getPinBarUp(ema2, ema1) fakeHighDn = high - open fakeLowDn = close - low pinHeightDn = height - min(fakeHighDn, fakeLowDn) getPinBarDn(ema1, ema2) => open > close and ((fakeHighDn > fakeLowDn * 2 and bodyHeight > fakeLowDn and high >= ema1 and close < ema1 and open < ema1 and close < ema2 and open < ema2 and open < (high - pinHeightDn * tail) and close < (high - pinHeightDn * tail)) or (fakeHighDn * 2 < fakeLowDn and bodyHeight > fakeHighDn and ema1 >= low and ema1 < close and ema2 < close and open > (open - pinHeightDn * tail1) and close > (open - pinHeightDn * tail1))) ? true : false pinBarDn1 = getPinBarDn(ema1, ema2) pinBarDn = pinBarDn1 ? pinBarDn1 : getPinBarDn(ema2, ema1) highlightBars = input(title="Highlight bars", type=bool, defval=true) enableAlerts = input(title="Enable alerts", type=bool, defval=true) //Temporary fix for alerts hl2Change = ((pinBarUp or pinBarDn) and enableAlerts) ? 999 : -999 plot(hl2 + hl2Change, style=area, transp=100, editable=false) barcolor((pinBarUp and highlightBars) ? lime : na, title="Bullish bar") barcolor((pinBarDn and highlightBars) ? red : na, title="Bearish bar")