Congestion Zone
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HLong Tran

//@version=4
study("Congestion Zone", overlay = true, max_boxes_count = 500)

ZoneColor = input(defval = color.new(color.orange, 70), title = "Color")

var aCZ = array.new_float(0)

congestionCondtion = close >= low[1] and close <= high[1] and open >= low[1] and open <= high[1]

if ( congestionCondtion == true )
    array.push(aCZ, open)
    array.push(aCZ, close)
else if( array.size(aCZ) < 6 )
    array.clear(aCZ)

if( array.size(aCZ) >= 6 and congestionCondtion == false )
    float maxCZ = array.max(aCZ)
    float minCZ = array.min(aCZ)
    box.new(bar_index - (array.size(aCZ) / 2), maxCZ, bar_index - 1, minCZ, bgcolor = ZoneColor, border_color = na)
    array.clear(aCZ)

