Bull & Bear Engulfing - 3 Strike and 180 Candles
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SenatorVonShaft

//@version=4
study("Bull & Bear Engulfing - 3 Strike and 180 Candles" , overlay = true)

candlperc = input(title="Bar Fullness Percentage",
     minval=50.00, maxval=100, step=0.1, defval=80) * 0.01
AvgBarBack = input(title = "Average Bar Backwds Candles", minval=1, step=1, defval=20)
avgcandlmult = input(title="Average Bar Height Multiptier",
     minval=0.1, maxval=20, step=0.1, defval=1.5)

ortBar = sma(abs(close - open) , AvgBarBack)
ortBarCond = abs(close - open) > avgcandlmult * ortBar
BiggerBar = abs (close - open) > abs (close [1] - open [1])
BullBar = close > open and hl2 > open and ((close - open) / (high - low)) >= candlperc and BiggerBar and ortBarCond
BearBar = close < open and hl2 < open and ((open - close) / (high - low)) >= candlperc and BiggerBar and ortBarCond
Bull3 = BullBar and close[1] < open [1] and close[2] < open [2] and close[3] < open [3] and close > open [3]
Bear3 = BearBar and close[1] > open [1] and close[2] > open [2] and close[3] > open [3] and close < open [3]
Bull180 = BearBar[1] and close > open and abs(open - close) > abs(open[1] - close [1])
Bear180 = BullBar[1] and close < open and abs(open - close) > abs(open[1] - close [1])

plotshape(BullBar,  style=shape.labelup , location= location.belowbar, color = color.green, transp = 10 ) //
plotshape(BearBar,  style=shape.labeldown, location=location.abovebar , color = color.red, transp = 10 )
plotshape(Bull3,  style=shape.labelup , location=location.belowbar, color = color.green, transp = 10 , text = "3S" , textcolor = color.white )
plotshape(Bear3,  style=shape.labeldown , location=location.abovebar , color = color.red, transp = 10 , text = "3S" , textcolor = color.white  )
plotshape(Bull180,  style=shape.labelup , location=location.belowbar, color = color.green, transp = 10 , text = "180" , textcolor = color.white  )
plotshape(Bear180,  style=shape.labeldown , location=location.abovebar , color = color.red, transp = 10 , text = "180" , textcolor = color.white  )
plot (ortBar , color = color.white)

