Simple Ichimoku Kinko Hyo Cloud
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RozaniGhani-RG

//@version=5
indicator('Simple Ichimoku Kinko Hyo Cloud', 'SIKHC', true)

// 0. Inputs
// 1. Type
// 2. Custom Function
// 3. Variables
// 4. Constructs

//#region ———————————————————— 0. Inputs
G0          = 'Tick to hide/show and input length'
boolTenkan  = input.bool(true,         '', group = G0, inline = '0')
boolKijun   = input.bool(true,         '', group = G0, inline = '1')
boolSenkouB = input.bool(true,         '', group = G0, inline = '2')
lenTenkan   = input.int(    9,   'Tenkan', group = G0, inline = '0', tooltip = 'Also known as Base Line')
lenKijun    = input.int(   26,    'Kijun', group = G0, inline = '1', tooltip = 'Also known as Conversion Line')
lenSenkouB  = input.int(   52, 'Senkou B', group = G0, inline = '2', tooltip = 'Also known as Leading Span B')
lenOffset   = input.int(   26,   'Offset', group = G0,               tooltip = 'Also known as Lagging Span.\nValue used to offset Senkou A, Senkou B and Chikou')

G1          = 'Tick to hide/show'
boolSenkouA = input.bool(true, 'Senkou A', group = G1, tooltip = 'Also known as Leading Span A')
boolChikou  = input.bool(true,   'Chikou', group = G1, tooltip = 'Also known as Close')
//#endregion

//#region ———————————————————— 1. Type
// @type        Used for range
// @field upper float value for upper
// @field lower float value for lower
// @field   sen float value for sen
type rng
    float upper = na
    float lower = na
    float   sen = na
//#endregion

//#region ———————————————————— 2. Custom Function
// @function createRng
// @param    len
// @returns  newRng
createRng(int len) =>
    newRng        = rng.new()
    newRng.upper := ta.highest(high, len)
    newRng.lower := ta.lowest(  low, len)
    newRng.sen   := math.avg(newRng.upper, newRng.lower)
    newRng
//#endregion

//#region ———————————————————— 3. Variables
tenkan  = createRng(lenTenkan)             // Also known as Base Line
kijun   = createRng(lenKijun)              // Also known as Conversion Line
senkouA = math.avg( tenkan.sen, kijun.sen) // Also known as Leading Span A
senkouB = createRng(lenSenkouB)            // Also known as Leading Span B
chikou  = close                            // Also known as close
//#endregion

//#region ———————————————————— 4. Constructs
TS = plot(boolTenkan  ?  tenkan.sen : na, 'Tenkan Sen')
KS = plot(boolKijun   ?   kijun.sen : na,  'Kijun sen', color.red)
SA = plot(boolSenkouA ?     senkouA : na,   'Senkou A', color.teal,  linewidth = 4, offset =  lenOffset - 1)
SB = plot(boolSenkouA ? senkouB.sen : na,   'Senkou B', color.red,   linewidth = 2, offset =  lenOffset - 1)
PC = plot(boolChikou  ?      chikou : na,     'Chikou', color.green, linewidth = 4, offset = -lenOffset + 1)

fill(SA, SB, senkouA > senkouB.sen ? color.new(color.teal, 90) : color.new(color.red, 90))
//#endregion