Inside Bar Highlight
// 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("Inside Bar Highlight", overlay = true, max_boxes_count = 500)

ZoneColor = input(defval = color.new(color.orange, 80), title = "Background Color")
BorderColor = input(defval = color.new(color.orange, 80), title = "Border Color")

var aCZ = array.new_float(0)

float highest = high[1]
float lowest = low[1]


if (array.size(aCZ) > 0) 
    highest := array.get(aCZ, 0)
    lowest := array.get(aCZ, 1)

insideBarCondtion = low >= lowest and low <= highest and high >= lowest and high <= highest      


if ( insideBarCondtion == true )
    array.push(aCZ, high[1])
    array.push(aCZ, low[1])

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

