OPEN-SOURCE SCRIPT

EL OJO DE DIOS - FINAL (ORDEN CORREGIDO)

147
//version=6
indicator("EL OJO DE DIOS - FINAL (ORDEN CORREGIDO)", overlay=true, max_boxes_count=500, max_lines_count=500, max_labels_count=500)

// --- 1. CONFIGURACIÓN ---
grpEMA = "Medias Móviles"
inpShowEMA = input.bool(true, "Mostrar EMAs", group=grpEMA)
inpEMA21 = input.int(21, "EMA 21", minval=1, group=grpEMA)
inpEMA50 = input.int(50, "EMA 50", minval=1, group=grpEMA)
inpEMA200 = input.int(200, "EMA 200", minval=1, group=grpEMA)

grpStrategy = "Estrategia"
inpTrendTF = input.string("Current", "Timeframe Señal", options=["Current", "15m", "1H"], group=grpStrategy)
inpADXFilter = input.bool(true, "Filtro ADX", group=grpStrategy)
inpADXPeriod = input.int(14, "Período ADX", group=grpStrategy)
inpADXLimit = input.int(20, "Límite ADX", group=grpStrategy)
inpRR = input.float(2.0, "Riesgo:Beneficio", group=grpStrategy)

grpVisuals = "Visuales"
inpShowPrevDay = input.bool(true, "Máx/Mín Ayer", group=grpVisuals)
inpShowNY = input.bool(true, "Sesión NY", group=grpVisuals)

// --- 2. VARIABLES ---
var float t1Price = na
var bool t1Bull = false
var bool t1Conf = false
var line slLine = na
var line tpLine = na

// Variables Prev Day
var float pdH = na
var float pdL = na
var line linePDH = na
var line linePDL = na

// Variables Session
var box nySessionBox = na

// --- 3. CÁLCULO ADX MANUAL ---
f_calcADX(_high, _low, _close, _len) =>
// True Range Manual
tr = math.max(_high - _low, math.abs(_high - _close[1]), math.abs(_low - _close[1]))

// Directional Movement
up = _high - _high[1]
down = _low[1] - _low
plusDM = (up > down and up > 0) ? up : 0.0
minusDM = (down > up and down > 0) ? down : 0.0

// Smoothed averages
atr = ta.rma(tr, _len)
plus = 100.0 * ta.rma(plusDM, _len) / atr
minus = 100.0 * ta.rma(minusDM, _len) / atr

// DX y ADX
sum = plus + minus
dx = sum == 0 ? 0.0 : 100.0 * math.abs(plus - minus) / sum
adx = ta.rma(dx, _len)
adx

// --- 4. CÁLCULO DE DATOS ---
ema21 = ta.ema(close, inpEMA21)
ema50 = ta.ema(close, inpEMA50)
ema200 = ta.ema(close, inpEMA200)

// MTF Logic
targetTF = inpTrendTF == "Current" ? timeframe.period : inpTrendTF == "15m" ? "15" : "60"

// CORRECCIÓN AQUÍ: Uso de argumentos nominales (gaps=, lookahead=) para evitar errores de orden
f_getSeries(src, tf) =>
tf == timeframe.period ? src : request.security(syminfo.tickerid, tf, src, gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_off)

tf_close = f_getSeries(close, targetTF)
tf_high = f_getSeries(high, targetTF)
tf_low = f_getSeries(low, targetTF)

tf_ema21 = ta.ema(tf_close, inpEMA21)
tf_ema50 = ta.ema(tf_close, inpEMA50)

// Calcular ADX
float tf_adx = f_calcADX(tf_high, tf_low, tf_close, inpADXPeriod)

// Cruces
bool crossUp = ta.crossover(tf_ema21, tf_ema50)
bool crossDown = ta.crossunder(tf_ema21, tf_ema50)
bool crossSignal = crossUp or crossDown
bool adxOk = inpADXFilter ? tf_adx > inpADXLimit : true

// --- 5. LÓGICA DE SEÑALES ---

if crossSignal and adxOk and barstate.isconfirmed
t1Price := tf_ema21
t1Bull := tf_ema21 > tf_ema50
t1Conf := false

if not na(slLine)
line.delete(slLine)
slLine := na
if not na(tpLine)
line.delete(tpLine)
tpLine := na

label.new(bar_index, high + (ta.atr(14)*0.5), text="CRUCE T1", color=t1Bull ? color.green : color.red, textcolor=color.white, size=size.small)

bool touch = false
if not na(t1Price) and not t1Conf
if t1Bull
touch := low <= t1Price and close >= t1Price
else
touch := high >= t1Price and close <= t1Price

if touch and barstate.isconfirmed
t1Conf := true

float atr = ta.atr(14)
float sl = t1Bull ? low - (atr*0.1) : high + (atr*0.1)
float dist = math.abs(t1Price - sl)
float tp = t1Bull ? t1Price + (dist * inpRR) : t1Price - (dist * inpRR)

label.new(bar_index, t1Price, text="ENTRADA", color=color.yellow, textcolor=color.black, size=size.small)

slLine := line.new(bar_index, sl, bar_index + 15, sl, color=color.red, style=line.style_dashed, width=2)
tpLine := line.new(bar_index, tp, bar_index + 15, tp, color=color.green, style=line.style_dashed, width=2)

// --- 6. GRÁFICO ---
col21 = ema21 > ema21[1] ? color.teal : color.maroon
col50 = ema50 > ema50[1] ? color.aqua : color.fuchsia
col200 = ema200 > ema200[1] ? color.blue : color.red

plot(inpShowEMA ? ema21 : na, "EMA21", color=col21, linewidth=2)
plot(inpShowEMA ? ema50 : na, "EMA50", color=col50, linewidth=2)
plot(inpShowEMA ? ema200 : na, "EMA200", color=col200, linewidth=2)

bgcolor(ema50 > ema200 ? color.new(color.green, 95) : color.new(color.red, 95))

// --- 7. SESIÓN NY ---
isNYSummer = (month(time) == 3 and dayofmonth(time) >= 14) or (month(time) > 3 and month(time) < 11)
hourOffset = isNYSummer ? 4 : 5
nyHour = (hour - hourOffset) % 24
bool isSession = nyHour >= 6 and nyHour < 11

if isSession and inpShowNY
if na(nySessionBox)
nySessionBox := box.new(bar_index, high, bar_index, low, bgcolor=color.new(color.blue, 92), border_color=color.new(color.white, 0))
else
box.set_right(nySessionBox, bar_index)
box.set_top(nySessionBox, math.max(high, box.get_top(nySessionBox)))
box.set_bottom(nySessionBox, math.min(low, box.get_bottom(nySessionBox)))

if not isSession and not na(nySessionBox)
box.delete(nySessionBox)
nySessionBox := na

// --- 8. MÁX/MÍN AYER ---
hCheck = request.security(syminfo.tickerid, "D", high[1], lookahead=barmerge.lookahead_on)
lCheck = request.security(syminfo.tickerid, "D", low[1], lookahead=barmerge.lookahead_on)

if not na(hCheck)
pdH := hCheck
if not na(lCheck)
pdL := lCheck

if barstate.islast and inpShowPrevDay
line.delete(linePDH)
line.delete(linePDL)
if not na(pdH)
linePDH := line.new(bar_index - 50, pdH, bar_index, pdH, color=color.green)
if not na(pdL)
linePDL := line.new(bar_index - 50, pdL, bar_index, pdL, color=color.red)

alertcondition(crossSignal, "Cruce T1", "Cruce Tendencia 1")
alertcondition(touch, "Entrada Confirmada", "Entrada Confirmada")

면책사항

해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.