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

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




//round function for rounding up to n decimal places
//Thanks to Proper Round Function - QuantNomad

roundn(x, n) =>
    mult = 1
    if n != 0
        for i = 1 to math.abs(n) by 1
            mult *= 10
            mult

    n >= 0 ? math.round(x * mult) / mult : math.round(x / mult) * mult
    
//calculating strength
green = roundn(((close-low)/(high-low) *100), 2)
red = roundn(((high-close)/(high-low)*100), 2)

if (close>open)
    l = label.new(x = bar_index,y = close,text=str.tostring(green) + " %",color=color.green,textcolor = color.white,style=label.style_label_up)
    label.set_yloc(l,yloc.belowbar)
if (open > close)
    l2 = label.new(x = bar_index,y = close,text=str.tostring(red)+ " %",color=color.red,textcolor=color.white,style=label.style_label_down)
    label.set_yloc(l2,yloc = yloc.abovebar)

