RicardoSantos

[RS]Max Range Grid V0

225 0 30
Grid based on maximum range (largest candle) avaible on loaded data.
Remove from Favorite Scripts Add to Favorite Scripts
//@version=2
study(title='[RS]Max Range Grid V0', shorttitle='MRG', overlay=true)
USE_ALT_TF = input(title='Use Alternative Timeframe?', type=bool, defval=false)
tf = input(title='Alternative Timeframe:', type=string, defval='D', confirm=false)

f_max_tr()=> _max_tr = na(_max_tr[1]) ? tr : tr > _max_tr[1] ? tr : _max_tr[1]
max_tr = USE_ALT_TF ? security(tickerid, tf, f_max_tr()) : f_max_tr()

r_center = round(close / max_tr) * max_tr

f_upper(_multiplier)=>r_center + max_tr * _multiplier
f_lower(_multiplier)=>r_center - max_tr * _multiplier

plot(title='ME', series=r_center, color=change(r_center) != 0 ? na : black, transp=0, linewidth=2)
plot(title='U01', series=f_upper(1), color=change(r_center) != 0 ? na : black, transp=0, linewidth=1)
plot(title='U02', series=f_upper(2), color=change(r_center) != 0 ? na : black, transp=0, linewidth=1)
plot(title='U03', series=f_upper(3), color=change(r_center) != 0 ? na : black, transp=0, linewidth=1)
plot(title='U04', series=f_upper(4), color=change(r_center) != 0 ? na : black, transp=0, linewidth=1)
plot(title='U05', series=f_upper(5), color=change(r_center) != 0 ? na : black, transp=0, linewidth=1)

plot(title='L01', series=f_lower(1), color=change(r_center) != 0 ? na : black, transp=0, linewidth=1)
plot(title='L02', series=f_lower(2), color=change(r_center) != 0 ? na : black, transp=0, linewidth=1)
plot(title='L03', series=f_lower(3), color=change(r_center) != 0 ? na : black, transp=0, linewidth=1)
plot(title='L04', series=f_lower(4), color=change(r_center) != 0 ? na : black, transp=0, linewidth=1)
plot(title='L05', series=f_lower(5), color=change(r_center) != 0 ? na : black, transp=0, linewidth=1)