Magic levels
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=5
indicator(title="Magic levels", shorttitle="Magic levels", overlay=true)

var float q1 = 0
var float q5 = 0
var float q3 = 0
var float q7 = 0
basePrice = math.floor(math.sqrt(close))

for i = (basePrice - 5) to (basePrice + 5)
    q1 := ((i + 0.125) * (i + 0.125))
    q5 := ((i + 0.625) * (i + 0.625))
    q3 := ((i + 0.375) * (i + 0.375))
    q7 := ((i + 0.875) * (i + 0.875))
    
    solidLineq1 = line.new(x1=bar_index[10], y1=q1, x2=bar_index, y2=q1)
    line.set_color(solidLineq1, color.rgb(170, 170, 170))
    line.set_extend(solidLineq1, extend.both)
    line.set_style(solidLineq1, line.style_solid)
    line.set_width(solidLineq1, 1)
    
    solidLineq5 = line.new(x1=bar_index[10], y1=q5, x2=bar_index, y2=q5)
    line.set_color(solidLineq5, color.rgb(170, 170, 170))
    line.set_extend(solidLineq5, extend.both)
    line.set_style(solidLineq5, line.style_solid)
    line.set_width(solidLineq5, 1)
    
    dashedLineq3 = line.new(x1=bar_index[10], y1=q3, x2=bar_index, y2=q3)
    line.set_color(dashedLineq3, color.rgb(170, 170, 170))
    line.set_extend(dashedLineq3, extend.both)
    line.set_style(dashedLineq3, line.style_dashed)
    line.set_width(dashedLineq3, 1)
    
    dashedLineq7 = line.new(x1=bar_index[10], y1=q7, x2=bar_index, y2=q7)
    line.set_color(dashedLineq7, color.rgb(170, 170, 170))
    line.set_extend(dashedLineq7, extend.both)
    line.set_style(dashedLineq7, line.style_dashed)
    line.set_width(dashedLineq7, 1)
