4C Inside/Outside Bar
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © FourC
//@version=5
//Adapted from Custom Candle color Inside/Outside candles, Highwave, Star Patt. by Craig_Stine

indicator("4C Inside/Outside Bar", "4C I/O Bar", overlay=true)
showdbibar = input.bool(true, 'Show Double Inside Bar Signal')
showdbobar = input.bool(false, 'Show Double Outside Bar Signal')
showoibar = input.bool(false, 'Show Inside + Outside Bar Signal')
showiobar = input.bool(false, 'Show Outside + Inside Bar Signal')
showiolabels = input.bool(false, 'Show I/O Bar Labels')

//Bar Signals
ibar = high <= high[1] and low >= low[1]
obar = high > high[1] and low < low[1]
dbibar = high <= high[1] and low >= low[1] and high[1] <= high[2] and low[1] >= low[2]
dbobar = high > high[1] and low < low[1] and high[1] > high[2] and low[1] < low[2]

//Inside Bar
barcolor(ibar ? color.blue : na, title='Inside Candle')
plotchar(ibar and showiolabels, title='Inside Bar', location=location.belowbar, color=color.new(color.blue, 0), size=size.tiny, text='IB')

//Outside Bar
barcolor(obar ? color.fuchsia : na, title='Outside Bar')
plotchar(obar and showiolabels, title='Outside Bar', location=location.belowbar, color=color.new(color.fuchsia, 0), size=size.tiny, text='OB')

//Double Inside Bar Signal
bgcolor(showdbibar and dbibar ? color.new(color.blue, 50) : na, title = 'Double Inside Bar')
plotchar(dbibar and showiolabels, title='Double Inside Bar', location=location.abovebar, color=color.new(color.white, 0), size=size.tiny, text='DIB')

//Double Outside Bar Signal
bgcolor(showdbobar and dbobar ? color.new(color.fuchsia, 50) : na, title = 'Double Outside Bar')
plotchar(dbobar and showiolabels, title='Double Outside Bar', location=location.abovebar, color=color.new(color.white, 0), size=size.tiny, text='DOB')

//Inside Bar + Outside Bar Signal
bgcolor(showoibar and obar and ibar[1] ? color.new(color.aqua, 50) : na, title = 'Inside Bar + Outside Bar')
plotchar(obar and ibar[1] and showiolabels, title='Inside + Outside Bar', location=location.abovebar, color=color.new(color.white, 0), size=size.tiny, text='IB+OB')

//Outside Bar + Inside Bar Signal
bgcolor(showiobar and ibar and obar[1] ? color.new(color.orange, 50) : na, title = 'Outside Bar + Inside Bar')
plotchar(ibar and obar[1] and showiolabels, title='Outside + Inside Bar', location=location.abovebar, color=color.new(color.white, 0), size=size.tiny, text='OB+IB')