RSI Multi TF strategy
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © anaryan

//@version=4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © anaryan


// ----------------------------------------------------------------------------
// RSI MultiTimeframe Indicator
// ----------------------------------------------------------------------------
// Plots 3 RSI (Weekly, Daily, 4h) at the same time, regardless of the Chart Timeframe.
// Highlights in green (or red) if all RSI are oversold (or overbought).
// Can trigger custom oversold and overbought alerts.

study(title="RSI Multi TF", shorttitle="RSI Multi TF (W, D, 4h)")
source = close
length = input(14, minval=1)
HighlightBreaches = input(true, title="Highlight Oversold and Overbought?", type=input.bool)

// RSI
RSI_1 = security(syminfo.tickerid, "W", rsi(source, length))
RSI_2 = security(syminfo.tickerid, "D", rsi(source, length))
RSI_3 = security(syminfo.tickerid, "240", rsi(source, length))

plot(RSI_3, title="4h", color=color.gray, linewidth=1)
plot(RSI_2, title="D", color=color.red, linewidth=2)
plot(RSI_1, title="W", color=color.yellow, linewidth=3)

UpperBand = input(70, title="Upper band")
LowerBand = input(30, title="Lower band")

b_color = RSI_3 > UpperBand and RSI_1 > UpperBand and RSI_2 > UpperBand ? color.red : 
   RSI_3 < LowerBand and RSI_1 < LowerBand and RSI_2 < LowerBand ? color.green : na
bgcolor(HighlightBreaches ? b_color : na, transp=50)

h0 = hline(UpperBand, title="Upper band", linestyle=hline.style_dashed, linewidth=1, color=color.red)
h1 = hline(LowerBand, title="Lower band", linestyle=hline.style_dashed, linewidth=1, color=color.green)
fill(h0, h1)

alertcondition(b_color == color.green, title='MultiOversold', message='Multi Oversold!')
alertcondition(b_color == color.red, title='MultiOverbought', message='Multi Overbought!')
