I'm trying to write a code where if a following bar of an inside bar didn't break the high or low or both of the previous bar of the inside bar, then that bar should also be marked as an inside bar with different bar colour
(https://i.stack.imgur.com/AMMow.jpg)
For e.g. in the above image after the large red bar there are 3 bars that did not break the high or the low of the red bar, I want to mark them as inside bars
As I'm a beginner at pine script and coding altogether I wrote a simple code to identify different bars and it worked except for inside bars. I tried using if function, for loop, custom functions, etc. Either I got an error or some different value altogether.
`
high_bar = high >= high[1] and low >= low[1]
low_bar = high <=high[1] and low <= low[1]
inside_bar = high < high[1] and low > low[1]
outside_bar = high > high[1] and low < low[1]
` I wrote this simple code for other bars but as you can guess it only identifies only first inside bar but not the following bars. If anyone can help me with this problem it'll be much appreciated. Thank you!