3 or more consecutive candles
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © bap666_

//@version=5

indicator("3+ candles", overlay=true)



bull_candle = close - open > 0
bear_candle = close - open < 0


tc = close[2] - open[2] > 0 //thirdcandle
sc = close[1] - open[1] > 0 //second candle
fc = close - open > 0 //first candle
threesame = tc == sc and sc == fc and tc == fc

three_bull = bull_candle and threesame
three_bear = bear_candle and threesame

barcolor(three_bear? #fbc02d: three_bull? #9575cd : na,-2)
barcolor(three_bear? #fbc02d: three_bull? #9575cd: na,-1)
barcolor(three_bear? #fbc02d: three_bull? #9575cd : na)