OPEN-SOURCE SCRIPT

STO

//version=6
indicator('Swing Trading & Opciones (RSI y VIX Dinámicos)', overlay = true)

// Entradas para colores personalizables con títulos específicos
color_rsi = input.color(color.blue, title = 'Color para Condición RSI < Umbral')
color_ema_both = input.color(color.lime, title = 'Color para EMAs Diarias y Semanales Positivas')
color_ema_weekly = input.color(color.green, title = 'Color para EMA Semanal Positiva')
color_default = input.color(color.red, title = 'Color para Tendencia Bajista')

// Calcular las EMAs del gráfico diario
ema20_daily = ta.ema(close, 20)
ema50_daily = ta.ema(close, 50)
ema200_daily = ta.ema(close, 200)

// Calcular las EMAs del gráfico semanal
ema10_weekly = request.security(syminfo.tickerid, 'W', ta.ema(close, 10))
ema20_weekly = request.security(syminfo.tickerid, 'W', ta.ema(close, 20))

// Calcular el RSI y sus umbrales dinámicos
rsi_length = 14
rsi_lookback = 252
rsi = ta.rsi(close, rsi_length)
rsi_mean = ta.sma(rsi, rsi_lookback)
rsi_stddev = ta.stdev(rsi, rsi_lookback)
rsi_oversold = rsi_mean - rsi_stddev
rsi_overbought = rsi_mean + rsi_stddev
rsi_status_dynamic = rsi < rsi_oversold ? 'Sobreventa' : rsi > rsi_overbought ? 'Sobrecompra' : 'Normal'

// Condición para pintar velas azul (sin usar umbral dinámico)
rsi_condition_static = rsi < 33

// Calcular el VIX y sus umbrales dinámicos
vix_symbol = 'CBOE:VIX'
vix_close = request.security(vix_symbol, 'D', close)
vix_lookback = 252
vix_mean = ta.sma(vix_close, vix_lookback)
vix_stddev = ta.stdev(vix_close, vix_lookback)
vix_low_threshold = vix_mean - vix_stddev
vix_high_threshold = vix_mean + vix_stddev
vix_status = vix_close < vix_low_threshold ? 'Bajo' : vix_close > vix_high_threshold ? 'Alto' : 'Normal'

// Marcar condición del VIX con un triángulo naranja bajo la vela
plotshape(vix_close > vix_high_threshold, style = shape.triangleup, color = color.orange, location = location.belowbar, title = 'VIX > Umbral')

// Calcular el ADX
adx_length = 14
adx_threshold = 25.0
[di_plus, di_minus, adx_value] = ta.dmi(adx_length, 14)
adx_status = adx_value > adx_threshold ? 'Tendencia Fuerte' : 'Sin Tendencia'

// Calcular el ATR de 14 días
atr = ta.atr(14)
atr_percentage = atr / close * 100 // ATR en porcentaje respecto al precio

// Calcular el Williams %R manualmente
length_williams = 14
high_williams = ta.highest(high, length_williams)
low_williams = ta.lowest(low, length_williams)
williams_r = (high_williams - close) / (high_williams - low_williams) * -100
williams_r_status = williams_r < -80 ? ' (Sobreventa)' : williams_r > -20 ? ' (Sobrecompra)' : ''
williams_r_color = williams_r < -80 ? color.green : williams_r > -20 ? color.red : color.white

// Determinar el color de las velas basado en prioridades
var color default_color = na
if rsi_condition_static
default_color := color_rsi // Prioridad 1: RSI estático
default_color
else if ema10_weekly <= ema20_weekly
default_color := color_default // Prioridad 2: EMAs semanales bajistas
default_color
else if ema20_daily > ema50_daily and ema10_weekly > ema20_weekly
default_color := color_ema_both // Prioridad 3: EMAs diarias y semanales positivas
default_color
else if ema10_weekly > ema20_weekly
default_color := color_ema_weekly // EMAs semanales positivas, pero diarias no cumplen
default_color
else
default_color := color_default // Caso predeterminado: rojo
default_color

// Cambiar el color de las velas
barcolor(default_color, title = 'Color de Velas Swing')

// Crear la tabla para mostrar los valores dinámicos
var table data_table = table.new(position.bottom_right, 2, 9, border_width = 1, frame_color = color.gray, frame_width = 1)

// Configurar la tabla (Encabezados y Valores)
if bar_index == 0 // Crear encabezados solo una vez
table.cell(data_table, 0, 0, 'Indicador', text_color = color.white, bgcolor = color.black, text_size = size.small, text_halign = text.align_center)
table.cell(data_table, 1, 0, 'Valor', text_color = color.white, bgcolor = color.black, text_size = size.small, text_halign = text.align_center)

// Fila 1: ADX
table.cell(data_table, 0, 1, 'ADX', text_color = color.white, bgcolor = color.black, text_halign = text.align_left, text_size = size.small)
table.cell(data_table, 1, 1, str.tostring(adx_value, '#.##') + ' (' + adx_status + ')', text_color = color.white, bgcolor = color.black, text_halign = text.align_left, text_size = size.small)

// Fila 2: RSI (Actual)
table.cell(data_table, 0, 2, 'RSI Actual', text_color = color.white, bgcolor = color.black, text_halign = text.align_left, text_size = size.small)
table.cell(data_table, 1, 2, str.tostring(rsi, '#.##') + ' (' + rsi_status_dynamic + ')', text_color = color.white, bgcolor = color.black, text_halign = text.align_left, text_size = size.small)

// Fila 3: Umbrales RSI
table.cell(data_table, 0, 3, 'Umbrales RSI', text_color = color.white, bgcolor = color.black, text_halign = text.align_left, text_size = size.small)
table.cell(data_table, 1, 3, 'Sobreventa: ' + str.tostring(rsi_oversold, '#.##') + ' / Sobrecompra: ' + str.tostring(rsi_overbought, '#.##'), text_color = color.white, bgcolor = color.black, text_halign = text.align_left, text_size = size.small)

// Fila 4: VIX (Actual)
table.cell(data_table, 0, 4, 'VIX Actual', text_color = color.white, bgcolor = color.black, text_halign = text.align_left, text_size = size.small)
table.cell(data_table, 1, 4, str.tostring(vix_close, '#.##') + ' (' + vix_status + ')', text_color = color.white, bgcolor = color.black, text_halign = text.align_left, text_size = size.small)

// Fila 5: Umbrales VIX
table.cell(data_table, 0, 5, 'Umbrales VIX', text_color = color.white, bgcolor = color.black, text_halign = text.align_left, text_size = size.small)
table.cell(data_table, 1, 5, 'Bajo: ' + str.tostring(vix_low_threshold, '#.##') + ' / Alto: ' + str.tostring(vix_high_threshold, '#.##'), text_color = color.white, bgcolor = color.black, text_halign = text.align_left, text_size = size.small)

// Fila 6: ATR
table.cell(data_table, 0, 6, 'ATR (14 días)', text_color = color.white, bgcolor = color.black, text_halign = text.align_left, text_size = size.small)
table.cell(data_table, 1, 6, str.tostring(atr, '#.##') + ' (' + str.tostring(atr_percentage, '#.##') + '%)', text_color = color.white, bgcolor = color.black, text_halign = text.align_left, text_size = size.small)

// Fila 7: Williams %R
table.cell(data_table, 0, 7, 'Williams %R', text_color = color.white, bgcolor = color.black, text_halign = text.align_left, text_size = size.small)
table.cell(data_table, 1, 7, str.tostring(williams_r, '#.##') + williams_r_status, text_color = williams_r_color, bgcolor = color.black, text_halign = text.align_left, text_size = size.small)
Bands and Channelsopciones

오픈 소스 스크립트

진정한 TradingView 정신에 따라, 이 스크립트의 저자는 트레이더들이 이해하고 검증할 수 있도록 오픈 소스로 공개했습니다. 저자에게 박수를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 출판물에서 이 코드를 재사용하는 것은 하우스 룰에 의해 관리됩니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

차트에 이 스크립트를 사용하시겠습니까?

면책사항