Covering Shadow Candle Pattern
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Mahdi_Fatemi1998 

//@version=5
indicator("Covering Shadow Candle Pattern", overlay=true) 


//detecting covering shadows
threeGreenCandles = (close[1] > open[1]) and (close[2] > open[2]) and (close[3] > open[3])
threeRedCandles = (close[1] < open[1]) and (close[2] < open[2]) and (close[3] < open[3])
coveringRedCandle = (low < low[1]) and (low < low[2]) and (low < low[3]) and (close < open) //remove the last term for test
coveringGreenCandle = (high > high[1]) and (high > high[2]) and (high > high[3]) and (close > open) //remove the last term for test
redCover = threeGreenCandles and coveringRedCandle
greenCover = threeRedCandles and coveringGreenCandle

//detecting supply and demand zones
threeGreenCandles2 = (close[6] > open[6]) and (close[5] > open[5]) and (close[4] > open[4])
threeRedCandles2 = (close[6] < open[6]) and (close[5] < open[5]) and (close[4] < open[4])
coveringRedCandle2 = (low[3] < low[6]) and (low[3] < low[5]) and (low[3] < low[4]) and (close[3] < open[3]) //remove the last term for test
coveringGreenCandle2 = (high[3] > high[6]) and (high[3] > high[5]) and (high[3] > high[6]) and (close[3] > open[3]) //remove the last term for test
redFollowing2 = close[2] < open[2]
greenFollowing2 = close[2] > open[2]
failureDoubleGreen2 = (close[1] > open[1]) and (close > open)
failuteDoubleRed2 = (close[1] < open[1]) and (close < open)
demandZone = threeGreenCandles2 and coveringRedCandle2 and redFollowing2 and failureDoubleGreen2
supplyZone = threeRedCandles2 and coveringGreenCandle2 and greenFollowing2 and failuteDoubleRed2

//plot covering shadows
plotshape(redCover, style=shape.triangledown, location=location.abovebar, color=color.red)
plotshape(greenCover, style=shape.triangleup, location=location.belowbar, color=color.green)

//plot zones
if demandZone
    box.new(
         left=bar_index - 3,
         right=bar_index + 10,
         top=high[3],
         bottom=low[2],
         bgcolor=color.new(color.white, 90))
if supplyZone
    box.new(
         left=bar_index - 3,
         right=bar_index + 10,
         top=high[2],
         bottom=low[3],
         bgcolor=color.new(color.white, 90))
