PROTECTED SOURCE SCRIPT

Gann 999

65
//version=5
indicator("Gann Square of Nine HA Pivot Levels", overlay=true)

// ===== USER INPUT =====
haPivot = input.float(3339.33, "HA Pivot")
degreeStep = input.int(45, "Degree Step (Default 45°)")

// ===== CALCULATIONS =====
root = math.sqrt(haPivot)
step = degreeStep / 360.0

// Function to calculate level
gannLevel(multiplier) =>
math.pow(root + (step * multiplier), 2)

// R levels
R1 = gannLevel(1)
R2 = gannLevel(2)
R3 = gannLevel(3)
R4 = gannLevel(4)
R5 = gannLevel(5)
R6 = gannLevel(6)
R7 = gannLevel(7)
R8 = gannLevel(8)
R9 = gannLevel(9)

// S levels
S1 = math.pow(root - (step * 1), 2)
S2 = math.pow(root - (step * 2), 2)
S3 = math.pow(root - (step * 3), 2)
S4 = math.pow(root - (step * 4), 2)
S5 = math.pow(root - (step * 5), 2)
S6 = math.pow(root - (step * 6), 2)
S7 = math.pow(root - (step * 7), 2)
S8 = math.pow(root - (step * 8), 2)
S9 = math.pow(root - (step * 9), 2)

// ===== PLOTTING =====
plot(haPivot, "HA Pivot", color=color.yellow, linewidth=2)

plot(R1, "R1", color=color.green)
plot(R2, "R2", color=color.green)
plot(R3, "R3", color=color.green)
plot(R4, "R4", color=color.green)
plot(R5, "R5", color=color.green)
plot(R6, "R6", color=color.green)
plot(R7, "R7", color=color.green)
plot(R8, "R8", color=color.green)
plot(R9, "R9", color=color.green)

plot(S1, "S1", color=color.red)
plot(S2, "S2", color=color.red)
plot(S3, "S3", color=color.red)
plot(S4, "S4", color=color.red)
plot(S5, "S5", color=color.red)
plot(S6, "S6", color=color.red)
plot(S7, "S7", color=color.red)
plot(S8, "S8", color=color.red)
plot(S9, "S9", color=color.red)

// ===== LABELS (last bar only) =====
if bar_index == last_bar_index
label.new(bar_index, R9, "R9", style=label.style_label_down, color=color.green, textcolor=color.white)
label.new(bar_index, R8, "R8", style=label.style_label_down, color=color.green, textcolor=color.white)
label.new(bar_index, R7, "R7", style=label.style_label_down, color=color.green, textcolor=color.white)
label.new(bar_index, R6, "R6", style=label.style_label_down, color=color.green, textcolor=color.white)
label.new(bar_index, R5, "R5", style=label.style_label_down, color=color.green, textcolor=color.white)
label.new(bar_index, R4, "R4", style=label.style_label_down, color=color.green, textcolor=color.white)
label.new(bar_index, R3, "R3", style=label.style_label_down, color=color.green, textcolor=color.white)
label.new(bar_index, R2, "R2", style=label.style_label_down, color=color.green, textcolor=color.white)
label.new(bar_index, R1, "R1", style=label.style_label_down, color=color.green, textcolor=color.white)

label.new(bar_index, S1, "S1", style=label.style_label_up, color=color.red, textcolor=color.white)
label.new(bar_index, S2, "S2", style=label.style_label_up, color=color.red, textcolor=color.white)
label.new(bar_index, S3, "S3", style=label.style_label_up, color=color.red, textcolor=color.white)
label.new(bar_index, S4, "S4", style=label.style_label_up, color=color.red, textcolor=color.white)
label.new(bar_index, S5, "S5", style=label.style_label_up, color=color.red, textcolor=color.white)
label.new(bar_index, S6, "S6", style=label.style_label_up, color=color.red, textcolor=color.white)
label.new(bar_index, S7, "S7", style=label.style_label_up, color=color.red, textcolor=color.white)
label.new(bar_index, S8, "S8", style=label.style_label_up, color=color.red, textcolor=color.white)
label.new(bar_index, S9, "S9", style=label.style_label_up, color=color.red, textcolor=color.white)

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.