Gann Square 4 Table Concept Alternate UI
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RozaniGhani-RG
// Inspired by The Tunnel Thru The Air Or Looking Back From 1940, written by WD Gann
// Page 195 - 198
//
// Related build
// https://www.tradingview.com/script/WMeyD4Sy-Gann-Square-4-Cross-Cardinal-Table-Concept/
// https://www.tradingview.com/script/mEzLbIKm-Gann-Square-9-Cross-Cardinal-Table-Concept/

//@version=5
indicator('Gann Square 4 Table Concept Alternate UI', shorttitle = 'GS4TCAU_SC')

// 0. Arrays
// 1. Variables
// 2. Custom functions
// 3. if statament
// 4. Inputs
// ————————————————————————————————————————————————————————————————————————————— 0. Arrays {
//                            0   1   2   3   4    5    6    7    8    9
arr_cardinal_45  = array.from(1,  6, 19, 40, 69, 106, 151, 204, 265, 334)
arr_cardinal_135 = array.from(2,  9, 24, 47, 78, 117, 164, 219, 282, 353)
arr_cardinal_225 = array.from(3, 12, 29, 54, 87, 128, 177, 234, 299, 372)
arr_cardinal_315 = array.from(4, 15, 34, 61, 96, 139, 190, 249, 316, 391)
// sort array
array.sort(arr_cardinal_45, order.descending)
// }
// ————————————————————————————————————————————————————————————————————————————— 1. Variables {
G1 = 'Cross Cardinal'
var testTable = table.new(position = position.middle_center, columns = 21, rows = 21, bgcolor = color.black, border_width = 1)
input_font = input.string('Small', 'Font Size',options = ['Tiny', 'Small', 'Normal', 'Large', 'Huge'])
font   = switch input_font
    'Tiny'  => size.tiny
    'Small' => size.small
    'Large' => size.large
    'Huge'  => size.huge
    => size.normal
// }
// ————————————————————————————————————————————————————————————————————————————— 2. Custom functions {
cell_default(int _column, int _row, _id, int _index)=>
    table.cell(testTable, _column, _row, str.tostring(array.get(_id, _index)), bgcolor = color.gray, text_color = color.black, text_size = font)
fun_set(_input, _column0, _row0, _column1, _row1, _column2, _row2, _column3, _row3, _color) =>
    if _input
        table.cell_set_bgcolor(testTable, _column0, _row0, _color)
        table.cell_set_bgcolor(testTable, _column1, _row1, _color)
        table.cell_set_bgcolor(testTable, _column2, _row2, _color)
        table.cell_set_bgcolor(testTable, _column3, _row3, _color)
// }
// ————————————————————————————————————————————————————————————————————————————— 3. if statament {
if barstate.islast
    for _id = 0 to 9
        cell_default(     _id,      _id, arr_cardinal_45,  _id)
        cell_default(11 + _id,  9 - _id, arr_cardinal_135, _id)
        cell_default(11 + _id, 11 + _id, arr_cardinal_225, _id)
        cell_default(9  - _id, 11 + _id, arr_cardinal_315, _id)
// }
// ————————————————————————————————————————————————————————————————————————————— 4. Inputs {
cardinal_0 = input(false, '  1,   2,   3,   4', group = G1, inline = '0'), c0  = input.color(color.red,     '', group = G1, inline =  '0')
cardinal_1 = input(false, '  6,   9,  12,  15', group = G1, inline = '1'), c1  = input.color(color.orange,  '', group = G1, inline =  '1')
cardinal_2 = input(false, ' 19,  24,  29,  34', group = G1, inline = '2'), c2  = input.color(color.yellow,  '', group = G1, inline =  '2')
cardinal_3 = input(false, ' 40,  47,  54,  61', group = G1, inline = '3'), c3  = input.color(color.green,   '', group = G1, inline =  '3')
cardinal_4 = input(false, ' 69,  78,  87,  96', group = G1, inline = '4'), c4  = input.color(color.teal,    '', group = G1, inline =  '4')
cardinal_5 = input(false, '106, 117, 128, 139', group = G1, inline = '5'), c5  = input.color(color.aqua,    '', group = G1, inline =  '5')
cardinal_6 = input(false, '151, 164, 177, 190', group = G1, inline = '6'), c6  = input.color(color.blue,    '', group = G1, inline =  '6')
cardinal_7 = input(false, '204, 219, 234, 249', group = G1, inline = '7'), c7  = input.color(color.purple,  '', group = G1, inline =  '7')
cardinal_8 = input(false, '265, 282, 299, 316', group = G1, inline = '8'), c8  = input.color(color.fuchsia, '', group = G1, inline =  '8')
cardinal_9 = input(false, '334, 353, 372, 391', group = G1, inline = '9'), c9  = input.color(#FFC0CB,       '', group = G1, inline =  '9')

arr_bool_cardinal = array.new_bool(10)
array.set(arr_bool_cardinal, 0, cardinal_0)
array.set(arr_bool_cardinal, 1, cardinal_1)
array.set(arr_bool_cardinal, 2, cardinal_2)
array.set(arr_bool_cardinal, 3, cardinal_3)
array.set(arr_bool_cardinal, 4, cardinal_4)
array.set(arr_bool_cardinal, 5, cardinal_5)
array.set(arr_bool_cardinal, 6, cardinal_6)
array.set(arr_bool_cardinal, 7, cardinal_7)
array.set(arr_bool_cardinal, 8, cardinal_8)
array.set(arr_bool_cardinal, 9, cardinal_9)

// input cardinal   45    135    125     135    color
//                  c  r   c  r   c   r  c  r
fun_set(cardinal_0, 9, 9, 11, 9, 11, 11, 9, 11, c0)
fun_set(cardinal_1, 8, 8, 12, 8, 12, 12, 8, 12, c1)
fun_set(cardinal_2, 7, 7, 13, 7, 13, 13, 7, 13, c2)
fun_set(cardinal_3, 6, 6, 14, 6, 14, 14, 6, 14, c3)
fun_set(cardinal_4, 5, 5, 15, 5, 15, 15, 5, 15, c4)
fun_set(cardinal_5, 4, 4, 16, 4, 16, 16, 4, 16, c5)
fun_set(cardinal_6, 3, 3, 17, 3, 17, 17, 3, 17, c6)
fun_set(cardinal_7, 2, 2, 18, 2, 18, 18, 2, 18, c7)
fun_set(cardinal_8, 1, 1, 19, 1, 19, 19, 1, 19, c8)
fun_set(cardinal_9, 0, 0, 20, 0, 20, 20, 0, 20, c9)
// }