本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Date & Season Highlight", overlay = true)
// --- Entradas de Configuración ---
group_mode = "Modo de Selección"
bool auto_current_month = input.bool(
title = "Auto-detectar mes actual (Live)",
defval = true,
group = group_mode,
tooltip = "Si está activo, anula la selección manual y resalta siempre el mes en curso a lo largo de la gráfica."
)
string sel_month = input.string(
title = "Mes a resaltar (Manual)",
defval = "Julio",
options = ["Todos", "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"],
group = "Filtro de Fecha Manual"
)
int sel_year = input.int(
title = "Año específico (0 = Todos)",
defval = 0,
minval = 0,
maxval = 2100,
group = "Filtro de Fecha Manual",
tooltip = "Pon 0 si quieres ver este mes marcado en todos los años."
)
color color_highlight = input.color(
title = "Color de la franja",
defval = color.new(color.blue, 85),
group = "Apariencia"
)
color color_text = input.color(
title = "Color del texto del año",
defval = color.gray,
group = "Apariencia"
)
// --- Lógica de Determinación del Mes Target ---
int manual_target_month = switch sel_month
"Enero" => 1
"Febrero" => 2
"Marzo" => 3
"Abril" => 4
"Mayo" => 5
"Junio" => 6
"Julio" => 7
"Agosto" => 8
"Septiembre" => 9
"Octubre" => 10
"Noviembre" => 11
"Diciembre" => 12
=> 0
// Si "Auto-detectar" está activo, toma month(timenow). Si no, usa el manual.
int target_month = auto_current_month ? month(timenow) : manual_target_month
int target_year = auto_current_month ? 0 : sel_year // En modo automático resalta todos los años
// --- Lógica de Detección ---
int current_bar_month = month(time, syminfo.timezone)
int current_bar_year = year(time, syminfo.timezone)
bool month_match = (target_month == 0) or (current_bar_month == target_month)
bool year_match = (target_year == 0) or (current_bar_year == target_year)
bool is_selected_period = month_match and year_match
// Detecta la primera vela en la que empieza la franja
bool is_period_start = is_selected_period and not is_selected_period[1]
// --- Renderizado ---
// 1. Color de fondo
bgcolor(is_selected_period ? color_highlight : na, title = "Franja del Periodo")
// 2. Impresión del Año
if is_period_start
label.new(
x = bar_index,
y = na,
text = str.tostring(current_bar_year),
yloc = yloc.abovebar,
color = color.new(color.white, 100), // Fondo transparente
textcolor = color_text,
style = label.style_label_down,
size = size.small
)