Range Marker
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © poch3ng

//@version=5
indicator("Range Marker", shorttitle="RM", overlay=true)
style_group = "Style"
setting_group = "Setting"
c_bar = input.int(title="Bar Back", defval=20, group=style_group)
c_color = input.color(title="Mark Color", defval=color.purple, group=style_group)
c_transparent = input.int(title="Transparent", defval=80, group=style_group)

c_bar_enabled = input.bool(title="Bar Count", defval=false, group=setting_group)
c_limit_enabled = input.bool(title="Limit Timeframe", defval=false, group=setting_group)
c_timeframe = input.timeframe(title="Timeframe Period", defval="60", group=setting_group)

f_countbar(period)=>
    bull_bar = 0
    for i=0 to period
        if(close[i] >= open[i])
            bull_bar +=1
    [bull_bar, period-bull_bar]

[bull, bear] = f_countbar(2*c_bar)

if(c_bar_enabled)
    lab = label.new(bar_index, na, str.tostring(bull/(2*c_bar)*100) + "%\n🠇", yloc = yloc.abovebar, style = label.style_none, textcolor = color.black, size = size.normal)
    label.delete(lab[1])

if(timeframe.period == c_timeframe or c_limit_enabled == false)
    myBox = box.new(left=bar_index-c_bar, top=ta.highest(close,c_bar),
         right=bar_index, bottom=ta.lowest(close,c_bar),
         bgcolor=color.new(c_color, c_transparent),
         border_width=0)
    box.delete(myBox[1])

    
