MT-RSI
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © rareSnow99686

//@version=4
study(title="MT-RSI", overlay=false, precision=2)
 
range = input(40, "Range", type=input.integer)

is_green = close >= open
is_red = is_green == false

m1 = security(syminfo.tickerid, "1", close)
m1_low = security(syminfo.tickerid, "1", lowest(m1, range))
m1_high = security(syminfo.tickerid, "1", highest(m1, range))

m5 = security(syminfo.tickerid, "5", close)
m5_low = security(syminfo.tickerid, "5", lowest(m5, range))
m5_high = security(syminfo.tickerid, "5", highest(m5, range))

m15 = security(syminfo.tickerid, "15", close)
m15_low = security(syminfo.tickerid, "15", lowest(m15, range))
m15_high = security(syminfo.tickerid, "15", highest(m15, range))

m60 = security(syminfo.tickerid, "60", close)
m60_low = security(syminfo.tickerid, "60", lowest(m60, range))
m60_high = security(syminfo.tickerid, "60", highest(m60, range))

h4 = security(syminfo.tickerid, "240", close)
h4_low = security(syminfo.tickerid, "240", lowest(h4, range))
h4_high = security(syminfo.tickerid, "240", highest(h4, range))

d1 = security(syminfo.tickerid, "1D", close)
d1_low = security(syminfo.tickerid, "1D", lowest(d1, range))
d1_high = security(syminfo.tickerid, "1D", highest(d1, range))

w1 = security(syminfo.tickerid, "1W", close)
w1_low = security(syminfo.tickerid, "1W", lowest(w1, range))
w1_high = security(syminfo.tickerid, "1W", highest(w1, range))

m1_change = min(100,max(0,(100 * ( (m1 - m5_low) / (m5_high - m5_low) ))))
m5_change = min(100,max(0,(100 * ( (m5 - m15_low) / (m15_high - m15_low) ))))
m15_change = min(100,max(0,(100 * ( (m15 - m60_low) / (m60_high - m60_low) ))))
m60_change = min(100,max(0,(100 * ( (m60 - h4_low) / (h4_high - h4_low) ))))
h4_change = min(100,max(0,(100 * ( (h4 - d1_low) / (d1_high - d1_low) ))))
d1_change = min(100,max(0,(100 * ( (d1 - w1_low) / (w1_high - w1_low) ))))
w1_change = min(100,max(0,(100 * ( (w1 - w1_low) / (w1_high - w1_low) ))))

upper_band = hline(100, "Upper Band", color=color.new(color.red,70), linestyle=hline.style_solid)
mid_band = hline(50, "Mid Band", color=color.new(color.white,70), linestyle=hline.style_dashed)
lower_band = hline(0, "Lower Band", color=color.new(color.green,70), linestyle=hline.style_solid)
fill(lower_band, upper_band, color=color.new(color.aqua,95), title="Noise")


plot(timeframe.isweekly or timeframe.isdaily or (timeframe.isminutes and timeframe.multiplier <= 864) ? w1_change : na, '1W', color.rgb(233, 30, 99), 2, plot.style_stepline)
plot(timeframe.isdaily or (timeframe.isminutes and timeframe.multiplier <= 864) ? d1_change : na, '1D', color.purple, 2, plot.style_stepline)
plot(timeframe.isminutes and timeframe.multiplier <= 240 ? h4_change : na, '4H', color.blue, 2, plot.style_stepline)
plot(timeframe.isminutes and timeframe.multiplier <= 60 ? m60_change : na, '1H', color.green, 2, plot.style_stepline)
plot(timeframe.isminutes and timeframe.multiplier <= 15 ? m15_change : na, '15M', color.orange, 2, plot.style_stepline)
plot(timeframe.isminutes and timeframe.multiplier <= 5 ? m5_change : na, '5M', color.yellow, 2, plot.style_stepline)
plot(timeframe.isminutes and timeframe.multiplier == 1 ? m1_change : na, '1M', color.red, 2, plot.style_stepline)
