Candle Imbalance
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © r_oshiro

//@version=5
indicator("Candle Imbalance", overlay = true)

period = input(120, "Period")

bullishBars = 0.0
bearishBars = 0.0

for offset = 0 to period - 1
    if close[offset] > open[offset]
        bullishBars := bullishBars + 1
    else
        bearishBars := bearishBars + 1


bullishPc = math.ceil((bullishBars / period) * 100)
bearishPc = math.ceil((bearishBars / period) * 100)

printTable(txt) => var table t = table.new(position.top_right, 1, 1), table.cell(t, 0, 0, txt, bgcolor = color.yellow)
printTable("•Cutrim Theory•\n----------------\n Bullish bars: " + str.tostring(bullishBars) + " (" + str.tostring(bullishPc) + "%) \nBearish Bars: " + str.tostring(bearishBars)+ " (" + str.tostring(bearishPc) + "%)")
