OPEN-SOURCE SCRIPT

Jim Sloman's Adam Theory - Second Reflection Line

86
//version=5
indicator("Jim Sloman's Adam Theory - Second Reflection Line", overlay=true, shorttitle="Adam", max_lines_count=500)

//────────────────────────────
// 📥 Inputs
//────────────────────────────
src = input.source(close, "Source")
forecast = input.int(250, "Forecast", minval=1, maxval=500)
linewidth = input.int(2, "Line Width")
linecolor = input.color(color.purple, "Line Color")
ls_input = input.string("Solid", "Line Style", options = ["Solid", "Dashed", "Dotted"])
show_lines = input.bool(true, "Show Reflection Lines")

//────────────────────────────
// 🎨 Estilo de línea (versión corregida)
//────────────────────────────
ls_style = if ls_input == "Dashed"
line.style_dashed
else if ls_input == "Dotted"
line.style_dotted
else
line.style_solid

//────────────────────────────
// 🧱 Array persistente para líneas
//────────────────────────────
var line[] lines = array.new_line()

//────────────────────────────
// ✏️ Función para dibujar línea
//────────────────────────────
f_draw_line(_x1, _y1, _x2, _y2) =>
l = line.new(_x1, _y1, _x2, _y2, xloc = xloc.bar_index)
line.set_color(l, linecolor)
line.set_width(l, linewidth)
line.set_style(l, ls_style)
array.push(lines, l)

//────────────────────────────
// 🧠 Lógica principal
//────────────────────────────
if barstate.islast
// Limpiar líneas si el usuario las oculta
if not show_lines
for l in lines
line.delete(l)
array.clear(lines)
else
ref = src

// Evitar errores si forecast excede barras disponibles
valid_forecast = math.min(forecast, bar_index)

// Crear o actualizar las líneas
if array.size(lines) == 0
for i = 0 to valid_forecast - 2
d1 = src
d2 = src[i + 1]
inv_d1 = ref - (d1 - ref)
inv_d2 = ref - (d2 - ref)
f_draw_line(bar_index + i, inv_d1, bar_index + i + 1, inv_d2)
else
for i = 0 to valid_forecast - 2
d1 = src
d2 = src[i + 1]
inv_d1 = ref - (d1 - ref)
inv_d2 = ref - (d2 - ref)
l = array.get(lines, i)
line.set_xy1(l, bar_index + i, inv_d1)
line.set_xy2(l, bar_index + i + 1, inv_d2)
// Actualiza estilo visual por si el usuario cambia inputs
line.set_color(l, linecolor)
line.set_width(l, linewidth)
line.set_style(l, ls_style)

免责声明

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.