Double Ichimoku Cloud with drop-down selectable lookback periods
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © lockeyj provided much of the original code.  Many other coders inspired my modications.  Thanks everyone.
// Edit: Ronbo

//@version=4
study(title="IL", overlay=true)

// Input options
showkumoborder   = input(true , "Show Kumu Border?")
showLagging      = input(true , "Show Chikou Span?")
bar = input(title="Allow Bar Color Change?", type=input.bool, defval=false)
ichisettings     = input("9-26-52-26", "Ichimoku Settings", input.string , options=["7-22-44-22", "8-24-48-24", "9-26-52-26", "10-30-60-30"])

tslen(ichisettings) =>
    if ichisettings == "7-22-44-22"
        7
    else
        if ichisettings == "8-24-48-24"
            8
        else
            if ichisettings == "9-26-52-26"    
                9
            else
                10
kslen(ichisettings) =>
    if ichisettings == "7-22-44-22"
        22
    else
        if ichisettings == "8-24-48-24"
            24
        else
            if ichisettings == "9-26-52-26"    
                26
            else
                30
sslen(ichisettings) =>
    if ichisettings == "7-22-44-22"
        44
    else
        if ichisettings == "8-24-48-24"
            48
        else
            if ichisettings == "9-26-52-26"    
                52
            else
                60
shift(ichisettings) =>
    if ichisettings == "7-22-44-22"
        22
    else
        if ichisettings == "8-24-48-24"
            24
        else
            if ichisettings == "9-26-52-26"    
                26
            else
                30

// Ichimoku Cloud #1
conversionLine1  = avg(lowest(tslen(ichisettings)), highest(tslen(ichisettings)))
baseLine1        = avg(lowest(kslen(ichisettings)), highest(kslen(ichisettings)))
leadLine1_1      = avg(conversionLine1, baseLine1)
leadLine2_1      = avg(lowest(sslen(ichisettings)), highest(sslen(ichisettings)))

// Ichimoku Cloud #2
conversionLine2  = avg(lowest(2*tslen(ichisettings)), highest(2*tslen(ichisettings)))
baseLine2        = avg(lowest(2*kslen(ichisettings)), highest(2*kslen(ichisettings)))
leadLine1_2      = avg(conversionLine2, baseLine2)
leadLine2_2      = avg(lowest(2*sslen(ichisettings)), highest(2*sslen(ichisettings)))
chikoucolor1     = iff(close[shift(ichisettings)] > ohlc4, color.red, color.green)

p1_1 = plot(leadLine1_1, offset = shift(ichisettings), color=color.new(color.gray,32), title="K#1L1")
p2_1 = plot(leadLine2_1, offset = shift(ichisettings), color=color.new(color.gray,32), title="K#1L2")
fill(p1_1, p2_1, color = leadLine1_1 > leadLine2_1 ? color.new(color.green,68) : color.new(color.red,68))

p1_2 = plot(leadLine1_2, offset = shift(ichisettings), color=color.new(color.gray,32), title="K#2L2")
p2_2 = plot(leadLine2_2, offset = shift(ichisettings), color=color.new(color.gray,32), title="K#2L2")
fill(p1_2, p2_2, color = leadLine1_2 > leadLine2_2 ? color.new(color.green,68) : color.new(color.red,68))

plot(showLagging ? ohlc4 : na, offset = -shift(ichisettings), color=chikoucolor1, title="Chikou Span")

// Cloud Borders
kumomax = max(leadLine1_1,leadLine2_1,leadLine1_2,leadLine2_2)
kumomin = min(leadLine1_1,leadLine2_1,leadLine1_2,leadLine2_2)
plot(showkumoborder and kumomax ? kumomax : na, title = 'K Max', style=plot.style_line, linewidth=2, offset = shift(ichisettings), color=color.new(color.black,38))
plot(showkumoborder and kumomin ? kumomin : na, title = 'K Min', style=plot.style_line, linewidth=2, offset = shift(ichisettings), color=color.new(color.black,38))

//Colors
bgcolor = close > kumomax[shift(ichisettings)] ? #2BFF00 : #B5000F
barcolor(bar ? bgcolor : na)
