RANGO
El indicador RANGO para TradingView
Marca el máximo, el mínimo y el centro de la noche y, a las 9:30 de Nueva York, dibuja la entrada con su objetivo y su stop.
Copiado. Ahora pégalo en el Editor Pine.
Descargar Rango.txt- En TradingView, abre el Editor Pine (abajo del gráfico).
- Borra lo que haya, pega el código y pulsa «Añadir al gráfico».
- Úsalo en el NQ de 1 a 5 minutos: marca el máximo, el mínimo y el centro de la noche (de 18:00 a 9:30 de Nueva York) y, a las 9:30, dibuja COMPRA o VENTA con su objetivo y su stop.
Por defecto, 100 puntos de stop y 76 de objetivo; se cambian en los ajustes del indicador.
Ver el código (148 líneas)
//@version=6
// RANGO · indicador de @crazi.nq
// Marca el máximo y el mínimo de la sesión de la noche (desde las 18:00 ET) hasta la apertura de Nueva York (9:30 ET) y su centro.
// A las 9:30: si el precio cerró por encima del centro, señal de COMPRA; si cerró por debajo, señal de VENTA.
// Dibuja la entrada, el objetivo y el stop en puntos, y avisa con una alerta.
// No es una recomendación de inversión: es la regla que probamos en el canal, para que la estudies tú.
indicator("RANGO · @crazi.nq", shorttitle = "RANGO", overlay = true, max_lines_count = 500, max_labels_count = 500)
// ───────────── Entradas ─────────────
grpH = "Horario"
rangeSess = input.session("1800-0930", "Sesión del rango", group = grpH,
tooltip = "Inicio-fin del rango. El fin es la hora de la señal (por defecto, la apertura de NY a las 9:30). Por defecto, toda la sesión de la noche desde las 18:00; para empezar a medianoche, pon 0000-0930.")
tz = input.string("America/New_York", "Zona horaria", group = grpH)
grpT = "Operación"
tpPts = input.float(76.0, "Objetivo (puntos)", minval = 0.01, step = 0.25, group = grpT)
slPts = input.float(100.0, "Stop (puntos)", minval = 0.01, step = 0.25, group = grpT)
showTrade = input.bool(true, "Dibujar entrada, objetivo y stop", group = grpT)
tradeMins = input.int(120, "Largo de esas líneas (minutos)", minval = 5, group = grpT)
grpD = "Dibujo"
colHi = input.color(color.new(#26a69a, 0), "Máximo", group = grpD)
colLo = input.color(color.new(#ef5350, 0), "Mínimo", group = grpD)
colMid = input.color(color.new(#ffb300, 0), "Centro", group = grpD)
colTp = input.color(color.new(#26a69a, 0), "Objetivo", group = grpD)
colSl = input.color(color.new(#ef5350, 0), "Stop", group = grpD)
lineW = input.int(2, "Grosor", minval = 1, maxval = 5, group = grpD)
showLabels = input.bool(true, "Etiquetas con precio", group = grpD)
showBg = input.bool(false, "Sombrear el rango", group = grpD)
// ───────────── Horas (formato "HHMM-HHMM") ─────────────
sH = int(str.tonumber(str.substring(rangeSess, 0, 2)))
sM = int(str.tonumber(str.substring(rangeSess, 2, 4)))
eH = int(str.tonumber(str.substring(rangeSess, 5, 7)))
eM = int(str.tonumber(str.substring(rangeSess, 7, 9)))
const int DAY_MS = 86400000
y = year(time, tz)
mo = month(time, tz)
d = dayofmonth(time, tz)
tStartToday = timestamp(tz, y, mo, d, sH, sM)
tEndToday = timestamp(tz, y, mo, d, eH, eM)
crosses = sH * 60 + sM > eH * 60 + eM // el rango cruza la medianoche (p. ej. 1800-0930)
int rStart = na
int rEnd = na
if crosses
if time >= tStartToday
rStart := tStartToday
rEnd := tEndToday + DAY_MS
else if time < tEndToday
rStart := tStartToday - DAY_MS
rEnd := tEndToday
else if time >= tStartToday and time < tEndToday
rStart := tStartToday
rEnd := tEndToday
inRange = not na(rStart)
// ───────────── Máximo, mínimo y centro ─────────────
var float rHi = na
var float rLo = na
var int curStart = na
var int curEnd = na
var line lnHi = na
var line lnLo = na
var line lnMid = na
var label lbHi = na
var label lbLo = na
var label lbMid = na
newRange = inRange and (na(curStart) or rStart != curStart)
if newRange
curStart := rStart
curEnd := rEnd
rHi := high
rLo := low
lnHi := line.new(time, high, rEnd, high, xloc = xloc.bar_time, color = colHi, width = lineW)
lnLo := line.new(time, low, rEnd, low, xloc = xloc.bar_time, color = colLo, width = lineW)
lnMid := line.new(time, (high + low) / 2, rEnd, (high + low) / 2, xloc = xloc.bar_time,
color = colMid, width = lineW, style = line.style_dashed)
if showLabels
lbHi := label.new(rEnd, high, "", xloc = xloc.bar_time, style = label.style_label_left,
color = color.new(colHi, 20), textcolor = color.white, size = size.small)
lbLo := label.new(rEnd, low, "", xloc = xloc.bar_time, style = label.style_label_left,
color = color.new(colLo, 20), textcolor = color.white, size = size.small)
lbMid := label.new(rEnd, (high + low) / 2, "", xloc = xloc.bar_time, style = label.style_label_left,
color = color.new(colMid, 20), textcolor = color.black, size = size.small)
else if inRange
rHi := math.max(rHi, high)
rLo := math.min(rLo, low)
mid = (rHi + rLo) / 2
if inRange
line.set_y1(lnHi, rHi)
line.set_y2(lnHi, rHi)
line.set_y1(lnLo, rLo)
line.set_y2(lnLo, rLo)
line.set_y1(lnMid, mid)
line.set_y2(lnMid, mid)
if showLabels
label.set_y(lbHi, rHi)
label.set_text(lbHi, "Máx " + str.tostring(rHi, format.mintick))
label.set_y(lbLo, rLo)
label.set_text(lbLo, "Mín " + str.tostring(rLo, format.mintick))
label.set_y(lbMid, mid)
label.set_text(lbMid, "Centro " + str.tostring(mid, format.mintick))
bgcolor(showBg and inRange ? color.new(color.blue, 92) : na, title = "Rango")
// ───────────── Señal a la hora de cierre del rango ─────────────
// Se decide al cierre de la última vela del rango (la de las 9:29 en 1 minuto).
isLastRangeBar = inRange and time_close >= curEnd
buySignal = isLastRangeBar and close > mid
sellSignal = isLastRangeBar and close < mid
var int pendingDir = 0
if buySignal
pendingDir := 1
else if sellSignal
pendingDir := -1
// En la vela de las 9:30 se dibuja la entrada (su apertura), el objetivo y el stop
if not inRange and pendingDir != 0
entry = open
tp = entry + pendingDir * tpPts
sl = entry - pendingDir * slPts
tEnd = time + tradeMins * 60000
isBuy = pendingDir == 1
label.new(time, isBuy ? low : high, isBuy ? "COMPRA" : "VENTA", xloc = xloc.bar_time,
style = isBuy ? label.style_label_up : label.style_label_down,
color = isBuy ? color.new(#26a69a, 0) : color.new(#ef5350, 0), textcolor = color.white, size = size.normal)
if showTrade
line.new(time, entry, tEnd, entry, xloc = xloc.bar_time, color = color.gray, width = 1)
line.new(time, tp, tEnd, tp, xloc = xloc.bar_time, color = colTp, width = lineW, style = line.style_dotted)
line.new(time, sl, tEnd, sl, xloc = xloc.bar_time, color = colSl, width = lineW, style = line.style_dotted)
if showLabels
label.new(tEnd, tp, "Objetivo " + str.tostring(tp, format.mintick), xloc = xloc.bar_time,
style = label.style_label_left, color = color.new(colTp, 20), textcolor = color.white, size = size.small)
label.new(tEnd, sl, "Stop " + str.tostring(sl, format.mintick), xloc = xloc.bar_time,
style = label.style_label_left, color = color.new(colSl, 20), textcolor = color.white, size = size.small)
pendingDir := 0
// ───────────── Alertas ─────────────
alertcondition(buySignal, "RANGO · compra", "RANGO: precio por encima del centro a la apertura de NY → COMPRA")
alertcondition(sellSignal, "RANGO · venta", "RANGO: precio por debajo del centro a la apertura de NY → VENTA")
Siguiente paso
Activa las notificaciones de @crazi.nq
Cada guía sale primero en un reel. Así te enteras de la siguiente el mismo día.
Abrir @crazi.nqMás guías gratis
Nueva✓ Ya la tienes
✓ Ya la tienes
✓ Ya la tienes
✓ Ya la tienes