OPEN-SOURCE SCRIPT
Calculadora Stop Promedio MNQ (10 Velas)

//version=5
indicator("Calculadora Stop Promedio MNQ (10 Velas) - Corregido", overlay=true, max_lines_count=50, max_labels_count=50)
// ---------- Parámetros ----------
len = input.int(10, "Velas para promedio", minval=1)
tick_size = input.float(0.25, "Tick size (MNQ = 0.25)")
show_label = input.bool(true, "Mostrar etiqueta")
show_line = input.bool(true, "Mostrar línea")
// ---------- Protección: esperar suficientes barras ----------
enoughBars = bar_index >= (len - 1)
// ---------- Cálculo stop promedio (alto - bajo) ----------
var float stopPromedio = na
if enoughBars
float suma = 0.0
for i = 0 to len - 1
suma += high - low
stopPromedio := suma / len
else
stopPromedio := na
// ---------- Conversion a ticks ----------
stopTicks = not na(stopPromedio) ? stopPromedio / tick_size : na
// ---------- Nivel donde se colocaría el stop (visual) ----------
yStop = not na(stopPromedio) ? close - stopPromedio : na
// ---------- Crear / actualizar línea ----------
// Usamos xloc.bar_index para coordenadas por barras
var line stopLine = na
if show_line and not na(yStop)
if na(stopLine)
stopLine := line.new(x1 = bar_index - 1, y1 = yStop, x2 = bar_index, y2 = yStop, xloc = xloc.bar_index, extend = extend.none, color = color.red, width = 2)
else
line.set_xy1(stopLine, bar_index - 1, yStop)
line.set_xy2(stopLine, bar_index, yStop)
line.set_color(stopLine, color.red)
else
// Si ocultamos o no hay yStop, borramos línea si existe
if not na(stopLine)
line.delete(stopLine)
stopLine := na
// ---------- Crear / actualizar etiqueta ----------
var label stopLabel = na
if show_label and not na(yStop) and enoughBars
txt = "Stop promedio: " + str.tostring(stopTicks, format.volume) + " ticks"
if na(stopLabel)
stopLabel := label.new(x = bar_index, y = yStop, text = txt, xloc = xloc.bar_index, style = label.style_label_left, color = color.new(color.red, 0), textcolor = color.white, size = size.small)
else
label.set_xy(stopLabel, bar_index, yStop)
label.set_text(stopLabel, txt)
else
if not na(stopLabel)
label.delete(stopLabel)
stopLabel := na
// ---------- Output en Data Window (opcional) ----------
plotchar(stopPromedio, title="Stop promedio (price units)", char=' ', display=display.none)
plotchar(stopTicks, title="Stop (ticks)", char=' ', display=display.none)
indicator("Calculadora Stop Promedio MNQ (10 Velas) - Corregido", overlay=true, max_lines_count=50, max_labels_count=50)
// ---------- Parámetros ----------
len = input.int(10, "Velas para promedio", minval=1)
tick_size = input.float(0.25, "Tick size (MNQ = 0.25)")
show_label = input.bool(true, "Mostrar etiqueta")
show_line = input.bool(true, "Mostrar línea")
// ---------- Protección: esperar suficientes barras ----------
enoughBars = bar_index >= (len - 1)
// ---------- Cálculo stop promedio (alto - bajo) ----------
var float stopPromedio = na
if enoughBars
float suma = 0.0
for i = 0 to len - 1
suma += high - low
stopPromedio := suma / len
else
stopPromedio := na
// ---------- Conversion a ticks ----------
stopTicks = not na(stopPromedio) ? stopPromedio / tick_size : na
// ---------- Nivel donde se colocaría el stop (visual) ----------
yStop = not na(stopPromedio) ? close - stopPromedio : na
// ---------- Crear / actualizar línea ----------
// Usamos xloc.bar_index para coordenadas por barras
var line stopLine = na
if show_line and not na(yStop)
if na(stopLine)
stopLine := line.new(x1 = bar_index - 1, y1 = yStop, x2 = bar_index, y2 = yStop, xloc = xloc.bar_index, extend = extend.none, color = color.red, width = 2)
else
line.set_xy1(stopLine, bar_index - 1, yStop)
line.set_xy2(stopLine, bar_index, yStop)
line.set_color(stopLine, color.red)
else
// Si ocultamos o no hay yStop, borramos línea si existe
if not na(stopLine)
line.delete(stopLine)
stopLine := na
// ---------- Crear / actualizar etiqueta ----------
var label stopLabel = na
if show_label and not na(yStop) and enoughBars
txt = "Stop promedio: " + str.tostring(stopTicks, format.volume) + " ticks"
if na(stopLabel)
stopLabel := label.new(x = bar_index, y = yStop, text = txt, xloc = xloc.bar_index, style = label.style_label_left, color = color.new(color.red, 0), textcolor = color.white, size = size.small)
else
label.set_xy(stopLabel, bar_index, yStop)
label.set_text(stopLabel, txt)
else
if not na(stopLabel)
label.delete(stopLabel)
stopLabel := na
// ---------- Output en Data Window (opcional) ----------
plotchar(stopPromedio, title="Stop promedio (price units)", char=' ', display=display.none)
plotchar(stopTicks, title="Stop (ticks)", char=' ', display=display.none)
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.