Gann Square of 9
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © OztheWoz

//@version=4
study("Gann Squares", overlay=true)

// ---Inputs---
keyprice = input(1.0, "Starting Price")
intlen   = input(1.0, "Interval Length")

// ---Calculations---
val1 = keyprice
val2 = keyprice + (1 * intlen)
val3 = keyprice + (2 * intlen)
val4 = keyprice + (3 * intlen)
val5 = keyprice + (4 * intlen)
val6 = keyprice + (5 * intlen)
val7 = keyprice + (6 * intlen)
val8 = keyprice + (7 * intlen)
val9 = keyprice + (8 * intlen)
val10 = keyprice + (9 * intlen)
val11 = keyprice + (10 * intlen)
val12 = keyprice + (11 * intlen)
val13 = keyprice + (12 * intlen)
val14 = keyprice + (13 * intlen)
val15 = keyprice + (14 * intlen)
val16 = keyprice + (15 * intlen)
val17 = keyprice + (16 * intlen)
val18 = keyprice + (17 * intlen)
val19 = keyprice + (18 * intlen)
val20 = keyprice + (19 * intlen)
val21 = keyprice + (20 * intlen)
val22 = keyprice + (21 * intlen)
val23 = keyprice + (22 * intlen)
val24 = keyprice + (23 * intlen)
val25 = keyprice + (24 * intlen)
val26 = keyprice + (25 * intlen)
val27 = keyprice + (26 * intlen)
val28 = keyprice + (27 * intlen)
val29 = keyprice + (28 * intlen)
val30 = keyprice + (29 * intlen)
val31 = keyprice + (30 * intlen)
val32 = keyprice + (31 * intlen)
val33 = keyprice + (32 * intlen)
val34 = keyprice + (33 * intlen)
val35 = keyprice + (34 * intlen)
val36 = keyprice + (35 * intlen)
val37 = keyprice + (36 * intlen)
val38 = keyprice + (37 * intlen)
val39 = keyprice + (38 * intlen)
val40 = keyprice + (39 * intlen)
val41 = keyprice + (40 * intlen)
val42 = keyprice + (41 * intlen)
val43 = keyprice + (42 * intlen)
val44 = keyprice + (43 * intlen)
val45 = keyprice + (44 * intlen)
val46 = keyprice + (45 * intlen)
val47 = keyprice + (46 * intlen)
val48 = keyprice + (47 * intlen)
val49 = keyprice + (48 * intlen)
val50 = keyprice + (49 * intlen)
val51 = keyprice + (50 * intlen)
val52 = keyprice + (51 * intlen)
val53 = keyprice + (52 * intlen)
val54 = keyprice + (53 * intlen)
val55 = keyprice + (54 * intlen)
val56 = keyprice + (55 * intlen)
val57 = keyprice + (56 * intlen)
val58 = keyprice + (57 * intlen)
val59 = keyprice + (58 * intlen)
val60 = keyprice + (59 * intlen)
val61 = keyprice + (60 * intlen)
val62 = keyprice + (61 * intlen)
val63 = keyprice + (62 * intlen)
val64 = keyprice + (63 * intlen)
val65 = keyprice + (64 * intlen)
val66 = keyprice + (65 * intlen)
val67 = keyprice + (66 * intlen)
val68 = keyprice + (67 * intlen)
val69 = keyprice + (68 * intlen)
val70 = keyprice + (69 * intlen)
val71 = keyprice + (70 * intlen)
val72 = keyprice + (71 * intlen)
val73 = keyprice + (72 * intlen)
val74 = keyprice + (73 * intlen)
val75 = keyprice + (74 * intlen)
val76 = keyprice + (75 * intlen)
val77 = keyprice + (76 * intlen)
val78 = keyprice + (77 * intlen)
val79 = keyprice + (78 * intlen)
val80 = keyprice + (79 * intlen)
val81 = keyprice + (80 * intlen)


gann9clr = color.new(#CFCFCF, 80)
cardcrossclr = color.new(color.yellow, 60)
ordcrossclr  = color.new(color.aqua,   60)
gann9 = table.new(position=position.middle_right, columns=10, rows= 10, bgcolor=gann9clr)
table.cell(gann9, 5, 5, tostring(val1), text_color=color.white, bgcolor=cardcrossclr)
table.cell(gann9, 4, 5, tostring(val2), text_color=color.white, bgcolor=ordcrossclr)
table.cell(gann9, 4, 4, tostring(val3), text_color=color.white, bgcolor=cardcrossclr)
table.cell(gann9, 5, 4, tostring(val4), text_color=color.white, bgcolor=ordcrossclr)
table.cell(gann9, 6, 4, tostring(val5), text_color=color.white, bgcolor=cardcrossclr)
table.cell(gann9, 6, 5, tostring(val6), text_color=color.white, bgcolor=ordcrossclr)
table.cell(gann9, 6, 6, tostring(val7), text_color=color.white, bgcolor=cardcrossclr)
table.cell(gann9, 5, 6, tostring(val8), text_color=color.white, bgcolor=ordcrossclr)
table.cell(gann9, 4, 6, tostring(val9), text_color=color.white, bgcolor=cardcrossclr)
table.cell(gann9, 3, 6, tostring(val10), text_color=color.white)
table.cell(gann9, 3, 5, tostring(val11), text_color=color.white, bgcolor=ordcrossclr)
table.cell(gann9, 3, 4, tostring(val12), text_color=color.white)
table.cell(gann9, 3, 3, tostring(val13), text_color=color.white, bgcolor=cardcrossclr)
table.cell(gann9, 4, 3, tostring(val14), text_color=color.white)
table.cell(gann9, 5, 3, tostring(val15), text_color=color.white, bgcolor=ordcrossclr)
table.cell(gann9, 6, 3, tostring(val16), text_color=color.white)
table.cell(gann9, 7, 3, tostring(val17), text_color=color.white, bgcolor=cardcrossclr)
table.cell(gann9, 7, 4, tostring(val18), text_color=color.white)
table.cell(gann9, 7, 5, tostring(val19), text_color=color.white, bgcolor=ordcrossclr)
table.cell(gann9, 7, 6, tostring(val20), text_color=color.white)
table.cell(gann9, 7, 7, tostring(val21), text_color=color.white, bgcolor=cardcrossclr)
table.cell(gann9, 6, 7, tostring(val22), text_color=color.white)
table.cell(gann9, 5, 7, tostring(val23), text_color=color.white, bgcolor=ordcrossclr)
table.cell(gann9, 4, 7, tostring(val24), text_color=color.white)
table.cell(gann9, 3, 7, tostring(val25), text_color=color.white, bgcolor=cardcrossclr)
table.cell(gann9, 2, 7, tostring(val26), text_color=color.white)
table.cell(gann9, 2, 6, tostring(val27), text_color=color.white)
table.cell(gann9, 2, 5, tostring(val28), text_color=color.white, bgcolor=ordcrossclr)
table.cell(gann9, 2, 4, tostring(val29), text_color=color.white)
table.cell(gann9, 2, 3, tostring(val30), text_color=color.white)
table.cell(gann9, 2, 2, tostring(val31), text_color=color.white, bgcolor=cardcrossclr)
table.cell(gann9, 3, 2, tostring(val32), text_color=color.white)
table.cell(gann9, 4, 2, tostring(val33), text_color=color.white)
table.cell(gann9, 5, 2, tostring(val34), text_color=color.white, bgcolor=ordcrossclr)
table.cell(gann9, 6, 2, tostring(val35), text_color=color.white)
table.cell(gann9, 7, 2, tostring(val36), text_color=color.white)
table.cell(gann9, 8, 2, tostring(val37), text_color=color.white, bgcolor=cardcrossclr)
table.cell(gann9, 8, 3, tostring(val38), text_color=color.white)
table.cell(gann9, 8, 4, tostring(val39), text_color=color.white)
table.cell(gann9, 8, 5, tostring(val40), text_color=color.white, bgcolor=ordcrossclr)
table.cell(gann9, 8, 6, tostring(val51), text_color=color.white)
table.cell(gann9, 8, 7, tostring(val52), text_color=color.white)
table.cell(gann9, 8, 8, tostring(val53), text_color=color.white, bgcolor=cardcrossclr)
table.cell(gann9, 7, 8, tostring(val54), text_color=color.white)
table.cell(gann9, 6, 8, tostring(val55), text_color=color.white)
table.cell(gann9, 5, 8, tostring(val56), text_color=color.white, bgcolor=ordcrossclr)
table.cell(gann9, 4, 8, tostring(val57), text_color=color.white)
table.cell(gann9, 3, 8, tostring(val58), text_color=color.white)
table.cell(gann9, 2, 8, tostring(val59), text_color=color.white, bgcolor=cardcrossclr)
table.cell(gann9, 1, 8, tostring(val50), text_color=color.white)
table.cell(gann9, 1, 7, tostring(val51), text_color=color.white)
table.cell(gann9, 1, 6, tostring(val52), text_color=color.white)
table.cell(gann9, 1, 5, tostring(val53), text_color=color.white, bgcolor=ordcrossclr)
table.cell(gann9, 1, 4, tostring(val54), text_color=color.white)
table.cell(gann9, 1, 3, tostring(val55), text_color=color.white)
table.cell(gann9, 1, 2, tostring(val56), text_color=color.white)
table.cell(gann9, 1, 1, tostring(val57), text_color=color.white, bgcolor=cardcrossclr)
table.cell(gann9, 2, 1, tostring(val58), text_color=color.white)
table.cell(gann9, 3, 1, tostring(val59), text_color=color.white)
table.cell(gann9, 4, 1, tostring(val60), text_color=color.white)
table.cell(gann9, 5, 1, tostring(val61), text_color=color.white, bgcolor=ordcrossclr)
table.cell(gann9, 6, 1, tostring(val62), text_color=color.white)
table.cell(gann9, 7, 1, tostring(val63), text_color=color.white)
table.cell(gann9, 8, 1, tostring(val64), text_color=color.white)
table.cell(gann9, 9, 1, tostring(val65), text_color=color.white, bgcolor=cardcrossclr)
table.cell(gann9, 9, 2, tostring(val66), text_color=color.white)
table.cell(gann9, 9, 3, tostring(val67), text_color=color.white)
table.cell(gann9, 9, 4, tostring(val68), text_color=color.white)
table.cell(gann9, 9, 5, tostring(val69), text_color=color.white, bgcolor=ordcrossclr)
table.cell(gann9, 9, 6, tostring(val70), text_color=color.white)
table.cell(gann9, 9, 7, tostring(val71), text_color=color.white)
table.cell(gann9, 9, 8, tostring(val72), text_color=color.white)
table.cell(gann9, 9, 9, tostring(val73), text_color=color.white, bgcolor=cardcrossclr)
table.cell(gann9, 8, 9, tostring(val74), text_color=color.white)
table.cell(gann9, 7, 9, tostring(val75), text_color=color.white)
table.cell(gann9, 6, 9, tostring(val76), text_color=color.white)
table.cell(gann9, 5, 9, tostring(val77), text_color=color.white, bgcolor=ordcrossclr)
table.cell(gann9, 4, 9, tostring(val78), text_color=color.white)
table.cell(gann9, 3, 9, tostring(val79), text_color=color.white)
table.cell(gann9, 2, 9, tostring(val80), text_color=color.white)
table.cell(gann9, 1, 9, tostring(val81), text_color=color.white, bgcolor=cardcrossclr)


