indicator("EA example", overlay=true) _v = input.string("1.0.1", title="Version", options=["1.0.1"], group="EA") _bullImb = input.bool(true, "Bullish Imbalance", group="Imbalances", tooltip="Show Bullish Imbalances") _bullCol = input.color(color.new(#2d6393,60), "Bg Color", group="Imbalances", inline="1") _bullColBorder = input.color(color.new(#1848cc,75), "     Border Color", group="Imbalances", inline="1") _bearImb = input.bool(true, "Bearish Imbalance", group="Imbalances", tooltip="Show Bearish Imbalances") _bearCol = input.color(color.new(#2d6393,60), "Bg Color", group="Imbalances", inline="2") _bearColBorder = input.color(color.new(#1848cc,75), "     Border Color", group="Imbalances", inline="2") _removeOld = input.bool(true, " Remove Mitigated", group="Options", tooltip="Option to either keep or remove the mitigate imbalances") _width = input.int(0, "Box Width", minval=0, maxval=500, group="Options", tooltip="Choose the width of the box") _totalCount = input.int(20, "Total Shown Imbalances", group="Options", tooltip="The total amount of imbalances allowed to be displayed on the chart") // Variables var bearBox = array.new_box() var bullBox = array.new_box() // Top Imbalance bearImb = low[2] <= open[1] and high >= close[1] bearGap = low[1] > high bearImbSize = low[2] - high if _bearImb and bearImb and bearImbSize > 0 or bearGap n = bearGap ? 1 : 2 array.push(bearBox, box.new(left=bar_index[1], top=low[n], right=bar_index+_width, bottom=high, bgcolor=_bearCol, border_color=_bearColBorder)) // Bottom Imbalance bullImb = high[2] >= open[1] and low <= close[1] bullImbSize = low - high[2] bullGap = high[1] < low if _bullImb and bullImb and bullImbSize > 0 or bullGap n = bullGap ? 1 : 2 array.push(bullBox, box.new(left=bar_index[1], top=low, right=bar_index+_width, bottom=high[n], bgcolor=_bullCol, border_color=_bullColBorder)) // Remove Mitigated remove_mitigate(arrayType, pos) => if array.size(arrayType) > 0 for i = array.size(arrayType) - 1 to 0 by 1 sbox = array.get(arrayType, i) top = box.get_top(sbox) bot = box.get_bottom(sbox) pass = pos =="Bull" ? low < bot + ((top - bot)/2) : high > top - ((top - bot)/2) if pass txt = pos =="Bull" ? "Bullish" : "Bearish" alert("Price (" + str.tostring(close) + ") inside "+txt+" Imbalance", alert.freq_once_per_bar) if _removeOld array.remove(arrayType, i) box.delete(sbox) // Run Functions remove_mitigate(bullBox, "Bull") remove_mitigate(bearBox, "Bear") // Remove Older Imb if array.size(bearBox) > _totalCount b = array.shift(bearBox) box.delete(b) if array.size(bullBox) > _totalCount b = array.shift(bullBox) box.delete(b)