OPEN-SOURCE SCRIPT

JJtrading

//version=5
indicator("Estrategia de Alto/Bajo Mejorada", overlay=true)

// Variables para almacenar altos y bajos
var float highestHigh = na
var float lowestLow = na
var float penultimateHigh = na
var float penultimateLow = na

// Definir períodos para los altos y bajos (ajusta el periodo según tu estrategia)
alto_mas_alto = ta.highest(high, 20)
bajo_mas_bajo = ta.lowest(low, 20)

// Actualizar los valores de altos y bajos
if (na(highestHigh) or high > highestHigh)
penultimateHigh := highestHigh
highestHigh := alto_mas_alto
if (na(lowestLow) or low < lowestLow)
penultimateLow := lowestLow
lowestLow := bajo_mas_bajo

// Dibujar líneas dinámicas para altos y bajos
var line highLine = line.new(na, na, na, na, color=color.green, width=2)
var line lowLine = line.new(na, na, na, na, color=color.red, width=2)
var line penultimateHighLine = line.new(na, na, na, na, color=color.green, width=1, style=line.style_dashed)
var line penultimateLowLine = line.new(na, na, na, na, color=color.red, width=1, style=line.style_dashed)

// Actualizar las posiciones de las líneas con los altos y bajos más recientes
line.set_xy1(highLine, bar_index[1], highestHigh)
line.set_xy2(highLine, bar_index, highestHigh)

line.set_xy1(lowLine, bar_index[1], lowestLow)
line.set_xy2(lowLine, bar_index, lowestLow)

line.set_xy1(penultimateHighLine, bar_index[1], penultimateHigh)
line.set_xy2(penultimateHighLine, bar_index, penultimateHigh)

line.set_xy1(penultimateLowLine, bar_index[1], penultimateLow)
line.set_xy2(penultimateLowLine, bar_index, penultimateLow)

// Condiciones de rompimiento para compra
compra = close > highestHigh
if (compra)
label.new(bar_index, high, text="Compra", style=label.style_label_up, color=color.green, textcolor=color.white)

// Condiciones de rompimiento para venta
venta = close < lowestLow
if (venta)
label.new(bar_index, low, text="Venta", style=label.style_label_down, color=color.red, textcolor=color.white)

// Opcional: Alerta cuando se cumpla la condición
alertcondition(compra, title="Alerta de Compra", message="Se ha roto el alto más alto, considera una compra.")
alertcondition(venta, title="Alerta de Venta", message="Se ha roto el bajo más bajo, considera una venta.")
Bands and Channels

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer