Senkou/Tenkan/Kijun Higher Time Frame
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © GiuseppeInzirillo

//@version=5
indicator("Senkou/Tenkan/Kijun Higher Time Frame", shorttitle="Ichimoku HTF", overlay=true)

// input declarations
tenkan_len = input.int(9, title="Tenkan Length")
kijun_len = input.int(26, title="Kijun Length")
senkou_b_period = input.int(52)

timeframe1 = input.timeframe("15", "Higher Timeframe1")
timeframe2 = input.timeframe("30", "Higher Timeframe2")
timeframe3 = input.timeframe("60", "Higher Timeframe3")
timeframe4 = input.timeframe("240", "Higher Timeframe4")
timeframe5 = input.timeframe("D", "Higher Timeframe5")
timeframe6 = input.timeframe("W", "Higher Timeframe6")
timeframe7 = input.timeframe("M", "Higher Timeframe7")

// Tenkan Definition
tenkan = math.avg(ta.highest(high,tenkan_len), ta.lowest(low, tenkan_len))

tenkan_high1 = request.security(syminfo.tickerid,timeframe1,tenkan)
tenkan_high2 = request.security(syminfo.tickerid,timeframe2,tenkan)
tenkan_high3 = request.security(syminfo.tickerid,timeframe3,tenkan)
tenkan_high4 = request.security(syminfo.tickerid,timeframe4,tenkan)
tenkan_high5 = request.security(syminfo.tickerid,timeframe5,tenkan)
tenkan_high6 = request.security(syminfo.tickerid,timeframe6,tenkan)
tenkan_high7 = request.security(syminfo.tickerid,timeframe7,tenkan)

// Kijun Definition
kijun = math.avg(ta.highest(high,kijun_len), ta.lowest(low, kijun_len))

kijun_high1 = request.security(syminfo.tickerid,timeframe1,kijun)
kijun_high2 = request.security(syminfo.tickerid,timeframe2,kijun)
kijun_high3 = request.security(syminfo.tickerid,timeframe3,kijun)
kijun_high4 = request.security(syminfo.tickerid,timeframe4,kijun)
kijun_high5 = request.security(syminfo.tickerid,timeframe5,kijun)
kijun_high6 = request.security(syminfo.tickerid,timeframe6,kijun)
kijun_high7 = request.security(syminfo.tickerid,timeframe7,kijun)

// Senkou Span A Definition
senkou_a = math.avg(tenkan, kijun)

ssa_high1 = request.security(syminfo.tickerid,timeframe1,senkou_a[kijun_len - 1])
ssa_high2 = request.security(syminfo.tickerid,timeframe2,senkou_a[kijun_len - 1])
ssa_high3 = request.security(syminfo.tickerid,timeframe3,senkou_a[kijun_len - 1])
ssa_high4 = request.security(syminfo.tickerid,timeframe4,senkou_a[kijun_len - 1])
ssa_high5 = request.security(syminfo.tickerid,timeframe5,senkou_a[kijun_len - 1])
ssa_high6 = request.security(syminfo.tickerid,timeframe6,senkou_a[kijun_len - 1])
ssa_high7 = request.security(syminfo.tickerid,timeframe7,senkou_a[kijun_len - 1])

// Senkou Span B Definition
senkou_b = math.avg(ta.highest(high,senkou_b_period), ta.lowest(low, senkou_b_period))

ssb_high1 = request.security(syminfo.tickerid,timeframe1,senkou_b[kijun_len - 1])
ssb_high2 = request.security(syminfo.tickerid,timeframe2,senkou_b[kijun_len - 1])
ssb_high3 = request.security(syminfo.tickerid,timeframe3,senkou_b[kijun_len - 1])
ssb_high4 = request.security(syminfo.tickerid,timeframe4,senkou_b[kijun_len - 1])
ssb_high5 = request.security(syminfo.tickerid,timeframe5,senkou_b[kijun_len - 1])
ssb_high6 = request.security(syminfo.tickerid,timeframe6,senkou_b[kijun_len - 1])
ssb_high7 = request.security(syminfo.tickerid,timeframe7,senkou_b[kijun_len - 1])

//senkou_a_plot = plot(senkou_a, offset = kijun_len - 1, color=#A5D6A7, title="Seknou Span A")
//senkou_b_plot = plot(senkou_b, offset = kijun_len - 1, color=#EF9A9A, title="Senkou Span B")

plot(tenkan_high1, color=#81c784, title="Tenkan 15M", linewidth=1)
plot(kijun_high1, color=#81c784, title="Kijun 15M", linewidth=1)
plot(ssa_high1, color=#81c784, title="SSA 15M", style=plot.style_circles, linewidth=1)
plot(ssb_high1, color=#81c784, title="SSB 15M", style=plot.style_circles, linewidth=1)

plot(tenkan_high2, color=#42bda8, title="Tenkan 30M", linewidth=1)
plot(kijun_high2, color=#42bda8, title="Kijun 30M", linewidth=1)
plot(ssa_high2, color=#42bda8, title="SSA 30M", style=plot.style_circles, linewidth=1)
plot(ssb_high2, color=#42bda8, title="SSB 30M", style=plot.style_circles, linewidth=1)

plot(tenkan_high3, color=color.gray, title="Tenkan H1", linewidth=1)
plot(kijun_high3, color=color.gray, title="Kijun H1", linewidth=1)
plot(ssa_high3, color=color.gray, title="SSA H1", style=plot.style_circles, linewidth=1)
plot(ssb_high3, color=color.gray, title="SSB H1", style=plot.style_circles, linewidth=1)

plot(tenkan_high4, color=color.orange, title="Tenkan H4", linewidth=1)
plot(kijun_high4, color=color.orange, title="Kijun H4", linewidth=1)
plot(ssa_high4, color=color.orange, title="SSA H4", style=plot.style_circles, linewidth=1)
plot(ssb_high4, color=color.orange, title="SSB H4", style=plot.style_circles, linewidth=1)

plot(tenkan_high5, color=color.maroon, title="Tenkan D", linewidth=1)
plot(kijun_high5, color=color.maroon, title="Kijun D", linewidth=1)
plot(ssa_high5, color=color.maroon, title="SSA D", style=plot.style_circles, linewidth=1)
plot(ssb_high5, color=color.maroon, title="SSB D", style=plot.style_circles, linewidth=1)

plot(tenkan_high6, color=color.olive, title="Tenkan W", linewidth=1)
plot(kijun_high6, color=color.olive, title="Kijun W", linewidth=1)
plot(ssa_high6, color=color.olive, title="SSA W", style=plot.style_circles, linewidth=1)
plot(ssb_high6, color=color.olive, title="SSB W", style=plot.style_circles, linewidth=1)

plot(tenkan_high7, color=color.purple, title="Tenkan M", linewidth=1)
plot(kijun_high7, color=color.purple, title="Kijun M", linewidth=1)
plot(ssa_high7, color=color.purple, title="SSA M", style=plot.style_circles, linewidth=1)
plot(ssb_high7, color=color.purple, title="SSB M", style=plot.style_circles, linewidth=1)
