[TK] Congestion pattern
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mentalRock19315

//@version=5
indicator("[TK] Congestion pattern", overlay = true)
nbbar = input.int(2,"Minimal number of bars for a congestion zone ?", minval=2, maxval=40)

barcongestion = true
baranalyse = 0

while barcongestion
    baranalyse := baranalyse + 1
    if close[baranalyse-1] < high[baranalyse] and close[baranalyse-1] > low[baranalyse]
        // on a bien une congestion
        na
    else
        barcongestion := false
baranalyse := baranalyse - 1

boxleft = bar_index-baranalyse
boxright = bar_index

if baranalyse >= nbbar
    max = high
    min = low
    for no = 1 to baranalyse
        if high[no] > max
            max := high[no]
        if low[no] < min
            min := low[no]
    box.new(left=boxleft, top=max, right=boxright, bottom=min, bgcolor = color.new(color.white,90), border_color=color.new(color.white,100))
