ProRealCode - Trading & Coding with ProRealTime™
Buenas tardes, me gustaría tener el Screener del indicador “ZigZag and SR” que Iván hizo en Diciembre del 2024, (ya lo pedí en su momento pero no salió como me hubiese gustado), en concreto me gustaría ser avisado cuando la onda LH (impulsiva) o la HL (correctiva) se plasmen en el gráfico de forma fija y me explico con un ejemplo: supongamos que se forma un alto HH, entonces el precio cuando comienza a corregir la subida, el indicador nombra dicha línea como LH (onda impulsiva), pero el problema es que si el precio sigue bajando y rompe la estructura del ZigZag hacia abajo ahora la etiqueta cambia a LL (bajo) y ya la LH no existe, si el Screener me avisó para ponerme alcista por el LH ya no me vale pues al final fue un LL; sólo dicha onda será nombrada LH (onda impulsiva) de forma permanente una vez que el ZigZag vuelva a tomar impulso y logre etiquetar el siguiente movimiento, el LH se quedará fijo; por eso me interesa que solo me avise cuando la onda LH o HL sean permanentes y no cambien, a continuación dejó la codificación del indicador, gracias y un saludo:
//————————————//
//PRC_ZigZag and SR
//version = 0
//03.12.2024
//Iván González @ http://www.prorealcode.com
//Sharing ProRealTime knowledge
//————————————//
// Inputs
//————————————//
prd=15
showSR=1 //Show Support and Resistance//Boolean// 0 means false 1 means True
showLabels=1 //Boolean// 0 means false 1 means True
showZZ=1 //Boolean// 0 means false 1 means True
atr=averagetruerange[14](close)
//————————————//
// Calculate Pivot High and Low
//————————————//
ph = high=highest[prd](high)
pl = low=lowest[prd](low)
//————————————//
// Calculate Direction
//————————————//
if ph and pl=0 then
dir=1
elsif pl and ph=0 then
dir=-1
else
dir=dir
endif
dirchanged=dir<>dir[1]
//————————————//
// Calculate ZizZag levels and x
//————————————//
if ph or pl then
if dirchanged then
if dir=1 then
$zigzag[t+1]=highest[prd](high)
$zigzagidx[t+1]=barindex
$dir[t+1]=1
t=t+1
elsif dir=-1 then
$zigzag[t+1]=lowest[prd](low)
$zigzagidx[t+1]=barindex
$dir[t+1]=-1
t=t+1
endif
else
if dir=1 and highest[prd](high)> $zigzag[t] then
$zigzag[t]=highest[prd](high)
$zigzagidx[t]=barindex
elsif dir=-1 and lowest[prd](low)< $zigzag[t] then
$zigzag[t]=lowest[prd](low)
$zigzagidx[t]=barindex
endif
endif
endif
//————————————//
// Draw ZigZag and Levels
//————————————//
$zigzag[0]=undefined
$zigzagidx[0]=undefined
if islastbarupdate then
if showZZ then
//Last ZigZag
drawsegment($zigzagidx[max(0,t-1)],$zigzag[max(0,t-1)],$zigzagidx[t],$zigzag[t])
endif
if showSR and $dir[t]=1 then
drawsegment($zigzagidx[t],$zigzag[t],barindex,$zigzag[t])style(dottedline,3)coloured(“green”)
drawsegment($zigzagidx[max(0,t-1)],$zigzag[max(0,t-1)],barindex,$zigzag[max(0,t-1)])style(dottedline,3)coloured(“red”)
if $zigzag[t]<$zigzag[t-2] then
drawtext(“HL”,$zigzagidx[t],$zigzag[t]+0.5*atr)coloured(“green”)
else
drawtext(“HH”,$zigzagidx[t],$zigzag[t]+0.5*atr)coloured(“green”)
endif
elsif showSR and $dir[t]=-1 then
drawsegment($zigzagidx[t],$zigzag[t],barindex,$zigzag[t])style(dottedline,3)coloured(“red”)
drawsegment($zigzagidx[max(0,t-1)],$zigzag[max(0,t-1)],barindex,$zigzag[max(0,t-1)])style(dottedline,3)coloured(“green”)
if $zigzag[t]<$zigzag[t-2] then
drawtext(“LL”,$zigzagidx[t],$zigzag[t]-0.5*atr)coloured(“red”)
else
drawtext(“LH”,$zigzagidx[t],$zigzag[t]-0.5*atr)coloured(“red”)
endif
endif
if showLabels then
drawpoint($zigzagidx[max(0,t-1)],$zigzag[max(0,t-1)],2)coloured(“blue”,100)
drawpoint($zigzagidx[t],$zigzag[t],2)coloured(“blue”,100)
endif
//Draw all ZigZag
for i=t-1 downto 3 do
if showZZ then
drawsegment($zigzagidx[max(0,i-1)],$zigzag[max(0,i-1)],$zigzagidx[i],$zigzag[i])
endif
if showSR and $dir[i]=1 then
drawsegment($zigzagidx[i],$zigzag[i],$zigzagidx[i+1],$zigzag[i])style(dottedline,3)coloured(“green”)
drawsegment($zigzagidx[max(0,i-1)],$zigzag[max(0,i-1)],$zigzagidx[i],$zigzag[max(0,i-1)])style(dottedline,3)coloured(“red”)
elsif showSR and $dir[i]=-1 then
drawsegment($zigzagidx[i],$zigzag[i],$zigzagidx[i+1],$zigzag[i])style(dottedline,3)coloured(“red”)
drawsegment($zigzagidx[max(0,i-1)],$zigzag[max(0,i-1)],$zigzagidx[i],$zigzag[max(0,i-1)])style(dottedline,3)coloured(“green”)
endif
if showLabels and $dir[i]=-1 and $zigzag[i]>$zigzag[i-2] then
drawtext(“LH”,$zigzagidx[i],$zigzag[i]-0.5*atr)coloured(“red”)
elsif showLabels and $dir[i]=-1 and $zigzag[i]<=$zigzag[i-2] then
drawtext(“LL”,$zigzagidx[i],$zigzag[i]-0.5*atr)coloured(“red”)
elsif showLabels and $dir[i]=1 and $zigzag[i]>$zigzag[i-2] then
drawtext(“HH”,$zigzagidx[i],$zigzag[i]+0.5*atr)coloured(“green”)
elsif showLabels and $dir[i]=1 and $zigzag[i]<=$zigzag[i-2] then
drawtext(“HL”,$zigzagidx[i],$zigzag[i]+0.5*atr)coloured(“green”)
endif
next
endif
//————————————//
return
Este es el indicador, modificado para que tanto el HL como el LH se impriman en el gráfico, en negrita, azul claro y rosa.
Observará que el HL y el LH se imprimen con retraso, ya que el indicador es un indicador de repintado:
// -----------------------------------------------------
// PRC_Ross Hook Pattern (Expo) by Zeiierman
// version = 0
// 18.02.2026
// Iván González @ www.prorealcode.com
// Sharing ProRealTime knowledge
// -----------------------------------------------------
// === PARAMETERS ===
// -----------------------------------------------------
//prd = 20 // Pivot period (high=long-term, low=short-term)
//dst = 20 // Min distance between point 2 and point 3
//
//showBreak = 1 // 1=Show break signal, 0=Hide
//showHook = 1 // 1=Show Ross Hook line, 0=Hide
//showPattern = 0 // 1=Show full pattern (1-2-3 + hooks), 0=Hide
//showPvts = 0 // 1=Show HH/HL/LH/LL labels, 0=Hide
// Break signal colors (RGB)
rBull = 49
gBull = 190
bBull = 12
rBear = 223
gBear = 61
bBear = 61
// -----------------------------------------------------
// === INITIALIZATION ===
// -----------------------------------------------------
once pvt0 = undefined
once pvt1 = undefined
once pvt2 = undefined
once pvt3 = undefined
once pvt4 = undefined
once idx0 = 0
once idx1 = 0
once idx2 = 0
once idx3 = 0
once idx4 = 0
once pos = 0
once hook = 1
// Label offset for positioning above/below price
atrVal = averagetruerange[14]
offset = atrVal * 0.5
// -----------------------------------------------------
// === PIVOT DETECTION ===
// -----------------------------------------------------
HLflag = 0
LHflag = 0
if barindex >= 2 * prd + 1 then
isPvtHi = (high[prd] = highest[2 * prd + 1](high))
isPvtLo = (low[prd] = lowest[2 * prd + 1](low))
// --- Pivot High detected ---
if isPvtHi and pos <= 0 then
// HH/LH label
if showPvts and pvt1 <> undefined then
if high[prd] > pvt1 then
drawtext("HH", barindex - prd, high[prd] + offset) coloured(128, 128, 128)
else
drawtext("LH", barindex - prd, high[prd] + offset) coloured(128, 128, 128)
LHflag = 1
endif
endif
// Shift arrays
pvt4 = pvt3
idx4 = idx3
pvt3 = pvt2
idx3 = idx2
pvt2 = pvt1
idx2 = idx1
pvt1 = pvt0
idx1 = idx0
pvt0 = high[prd]
idx0 = barindex - prd
pos = 1
endif
// --- Pivot Low detected ---
if isPvtLo and pos >= 0 then
// HL/LL label
if showPvts and pvt1 <> undefined then
if low[prd] > pvt1 then
drawtext("HL", barindex - prd, low[prd] - offset) coloured(128, 128, 128)
HLflag = 1
else
drawtext("LL", barindex - prd, low[prd] - offset) coloured(128, 128, 128)
endif
endif
// Shift arrays
pvt4 = pvt3
idx4 = idx3
pvt3 = pvt2
idx3 = idx2
pvt2 = pvt1
idx2 = idx1
pvt1 = pvt0
idx1 = idx0
pvt0 = low[prd]
idx0 = barindex - prd
pos = -1
endif
endif
// -----------------------------------------------------
// === BULLISH ROSS HOOK DETECTION ===
// -----------------------------------------------------
if pvt1 <> undefined and pvt4 <> undefined then
// Crossover: high crosses above pvt1
bullCross = (high > pvt1 and high[1] <= pvt1[1])
if bullCross and hook = 1 then
// pvt0 < pvt1 = correction after high (pullback)
if pvt0 < pvt1 then
// Validate structure: HH-HL sequence
// pvt1>pvt3 (higher high), pvt0>pvt2 (higher low)
// pvt2>pvt4 (higher low), pvt3>pvt2 (high above low)
if pvt1 > pvt3 and pvt0 > pvt2 and pvt2 > pvt4 and pvt3 > pvt2 then
if barindex - idx1 >= prd then
// Search for First Hook between point 4 and point 3
first = barindex - idx4
sec = barindex - idx3
foundHook = 0
hookBar = 0
for i = first downto sec do
if close[i] > pvt2 and (idx2 - barindex + i) >= dst then
foundHook = 1
hookBar = i
break
endif
next
if foundHook = 1 then
// --- Draw First Hook line ---
if showPattern then
drawsegment(barindex - hookBar, pvt2, idx2, pvt2) coloured(128, 128, 128) style(dottedline)
midFH = round((barindex - hookBar + idx2) / 2)
drawtext("First Hook", midFH, pvt2 - offset) coloured(128, 128, 128)
endif
// --- Draw Break signal ---
if showBreak then
drawpoint(barindex, high + offset, 3) coloured(rBull, gBull, bBull)
endif
// --- Draw Ross Hook line ---
if showHook then
drawsegment(idx3, pvt3, barindex, pvt3) coloured(128, 128, 128) style(dottedline)
midRH = round((barindex + idx3) / 2)
drawtext("Ross Hook", midRH, pvt3 - offset) coloured(128, 128, 128)
endif
// --- Draw full pattern ---
if showPattern then
// Second Hook line
drawsegment(idx1, pvt1, barindex, pvt1) coloured(128, 128, 128) style(dottedline)
midSH = round((barindex + idx1) / 2)
drawtext("Second Hook", midSH, pvt1 + offset) coloured(128, 128, 128)
// Pattern points 1-2-3
drawtext("1", idx4, pvt4 - offset) coloured(128, 128, 128)
drawtext("2", idx3, pvt3 + offset) coloured(128, 128, 128)
drawtext("3", idx2, pvt2 - offset) coloured(128, 128, 128)
// Zigzag connecting lines
drawsegment(idx2, pvt2, idx3, pvt3) coloured(128, 128, 128)
drawsegment(idx3, pvt3, idx4, pvt4) coloured(128, 128, 128)
endif
endif
hook = 0
endif
endif
endif
endif
endif
// -----------------------------------------------------
// === BEARISH ROSS HOOK DETECTION ===
// -----------------------------------------------------
if pvt1 <> undefined and pvt4 <> undefined then
// Crossunder: low crosses below pvt1
bearCross = (low < pvt1 and low[1] >= pvt1[1])
if bearCross and hook = 1 then
// pvt0 > pvt1 = correction after low (pullback up)
if pvt0 > pvt1 then
// Validate structure: LL-LH sequence
if pvt1 < pvt3 and pvt0 < pvt2 and pvt2 < pvt4 and pvt3 < pvt2 then
if barindex - idx1 >= prd then
// Search for First Hook between point 4 and point 3
first = barindex - idx4
sec = barindex - idx3
foundHook = 0
hookBar = 0
for i = first downto sec do
if close[i] < pvt2 and (idx2 - barindex + i) >= dst then
foundHook = 1
hookBar = i
break
endif
next
if foundHook = 1 then
// --- Draw First Hook line ---
if showPattern then
drawsegment(barindex - hookBar, pvt2, idx2, pvt2) coloured(128, 128, 128) style(dottedline)
midFH = round((barindex - hookBar + idx2) / 2)
drawtext("First Hook", midFH, pvt2 + offset) coloured(128, 128, 128)
endif
// --- Draw Break signal ---
if showBreak then
drawpoint(barindex, low - offset, 3) coloured(rBear, gBear, bBear)
endif
// --- Draw Ross Hook line ---
if showHook then
drawsegment(idx3, pvt3, barindex, pvt3) coloured(128, 128, 128) style(dottedline)
midRH = round((barindex + idx3) / 2)
drawtext("Ross Hook", midRH, pvt3 + offset) coloured(128, 128, 128)
endif
// --- Draw full pattern ---
if showPattern then
// Second Hook line
drawsegment(idx1, pvt1, barindex, pvt1) coloured(128, 128, 128) style(dottedline)
midSH = round((barindex + idx1) / 2)
drawtext("Second Hook", midSH, pvt1 - offset) coloured(128, 128, 128)
// Pattern points 1-2-3
drawtext("1", idx4, pvt4 + offset) coloured(128, 128, 128)
drawtext("2", idx3, pvt3 - offset) coloured(128, 128, 128)
drawtext("3", idx2, pvt2 + offset) coloured(128, 128, 128)
// Zigzag connecting lines
drawsegment(idx2, pvt2, idx3, pvt3) coloured(128, 128, 128)
drawsegment(idx3, pvt3, idx4, pvt4) coloured(128, 128, 128)
endif
endif
hook = 0
endif
endif
endif
endif
endif
// -----------------------------------------------------
// === HOOK RESET ===
// -----------------------------------------------------
// allow new detection when pivot structure changes
if pvt1 <> pvt1[1] then
hook = 1
endif
// -----------------------------------------------------
IF HLflag[1] THEN
DrawText("HL",BarIndex[1],high[1]+range[1],sansserif,bold,14) coloured("Cyan")
ELSiF LHflag[1] THEN
DrawText("LH",BarIndex[1],low[1]-range[1],sansserif,bold,14) coloured("Fuchsia")
ENDIF
return
Este es el screener para el indicador modificado, devolverá 1 cuando se imprima HL y 2 cuando se imprima LH:
// -----------------------------------------------------
// PRC_Ross Hook Pattern (Expo) by Zeiierman
// version = 0
// 18.02.2026
// Iván González @ www.prorealcode.com
// Sharing ProRealTime knowledge
// -----------------------------------------------------
// === PARAMETERS ===
// -----------------------------------------------------
prd = 20 // Pivot period (high=long-term, low=short-term)
dst = 20 // Min distance between point 2 and point 3
showBreak = 1 // 1=Show break signal, 0=Hide
showHook = 1 // 1=Show Ross Hook line, 0=Hide
showPattern = 0 // 1=Show full pattern (1-2-3 + hooks), 0=Hide
showPvts = 0 // 1=Show HH/HL/LH/LL labels, 0=Hide
// Break signal colors (RGB)
//rBull = 49
//gBull = 190
//bBull = 12
//rBear = 223
//gBear = 61
//bBear = 61
// -----------------------------------------------------
// === INITIALIZATION ===
// -----------------------------------------------------
once pvt0 = undefined
once pvt1 = undefined
once pvt2 = undefined
once pvt3 = undefined
once pvt4 = undefined
once idx0 = 0
once idx1 = 0
once idx2 = 0
once idx3 = 0
once idx4 = 0
once pos = 0
once hook = 1
// Label offset for positioning above/below price
//atrVal = averagetruerange[14]
//offset = atrVal * 0.5
// -----------------------------------------------------
// === PIVOT DETECTION ===
// -----------------------------------------------------
HLflag = 0
LHflag = 0
if barindex >= 2 * prd + 1 then
isPvtHi = (high[prd] = highest[2 * prd + 1](high))
isPvtLo = (low[prd] = lowest[2 * prd + 1](low))
// --- Pivot High detected ---
if isPvtHi and pos <= 0 then
// HH/LH label
if showPvts and pvt1 <> undefined then
if high[prd] > pvt1 then
//drawtext("HH", barindex - prd, high[prd] + offset) coloured(128, 128, 128)
else
//drawtext("LH", barindex - prd, high[prd] + offset) coloured(128, 128, 128)
LHflag = 1
endif
endif
// Shift arrays
pvt4 = pvt3
idx4 = idx3
pvt3 = pvt2
idx3 = idx2
pvt2 = pvt1
idx2 = idx1
pvt1 = pvt0
idx1 = idx0
pvt0 = high[prd]
idx0 = barindex - prd
pos = 1
endif
// --- Pivot Low detected ---
if isPvtLo and pos >= 0 then
// HL/LL label
if showPvts and pvt1 <> undefined then
if low[prd] > pvt1 then
//drawtext("HL", barindex - prd, low[prd] - offset) coloured(128, 128, 128)
HLflag = 1
else
//drawtext("LL", barindex - prd, low[prd] - offset) coloured(128, 128, 128)
endif
endif
// Shift arrays
pvt4 = pvt3
idx4 = idx3
pvt3 = pvt2
idx3 = idx2
pvt2 = pvt1
idx2 = idx1
pvt1 = pvt0
idx1 = idx0
pvt0 = low[prd]
idx0 = barindex - prd
pos = -1
endif
endif
// -----------------------------------------------------
// === BULLISH ROSS HOOK DETECTION ===
// -----------------------------------------------------
if pvt1 <> undefined and pvt4 <> undefined then
// Crossover: high crosses above pvt1
bullCross = (high > pvt1 and high[1] <= pvt1[1])
if bullCross and hook = 1 then
// pvt0 < pvt1 = correction after high (pullback)
if pvt0 < pvt1 then
// Validate structure: HH-HL sequence
// pvt1>pvt3 (higher high), pvt0>pvt2 (higher low)
// pvt2>pvt4 (higher low), pvt3>pvt2 (high above low)
if pvt1 > pvt3 and pvt0 > pvt2 and pvt2 > pvt4 and pvt3 > pvt2 then
if barindex - idx1 >= prd then
// Search for First Hook between point 4 and point 3
first = barindex - idx4
sec = barindex - idx3
foundHook = 0
//hookBar = 0
for i = first downto sec do
if close[i] > pvt2 and (idx2 - barindex + i) >= dst then
foundHook = 1
//hookBar = i
break
endif
next
if foundHook = 1 then
// --- Draw First Hook line ---
if showPattern then
//drawsegment(barindex - hookBar, pvt2, idx2, pvt2) coloured(128, 128, 128) style(dottedline)
//midFH = round((barindex - hookBar + idx2) / 2)
//drawtext("First Hook", midFH, pvt2 - offset) coloured(128, 128, 128)
endif
// --- Draw Break signal ---
if showBreak then
//drawpoint(barindex, high + offset, 3) coloured(rBull, gBull, bBull)
endif
// --- Draw Ross Hook line ---
if showHook then
//drawsegment(idx3, pvt3, barindex, pvt3) coloured(128, 128, 128) style(dottedline)
//midRH = round((barindex + idx3) / 2)
//drawtext("Ross Hook", midRH, pvt3 - offset) coloured(128, 128, 128)
endif
// --- Draw full pattern ---
if showPattern then
// Second Hook line
//drawsegment(idx1, pvt1, barindex, pvt1) coloured(128, 128, 128) style(dottedline)
//midSH = round((barindex + idx1) / 2)
//drawtext("Second Hook", midSH, pvt1 + offset) coloured(128, 128, 128)
// Pattern points 1-2-3
//drawtext("1", idx4, pvt4 - offset) coloured(128, 128, 128)
//drawtext("2", idx3, pvt3 + offset) coloured(128, 128, 128)
//drawtext("3", idx2, pvt2 - offset) coloured(128, 128, 128)
// Zigzag connecting lines
//drawsegment(idx2, pvt2, idx3, pvt3) coloured(128, 128, 128)
//drawsegment(idx3, pvt3, idx4, pvt4) coloured(128, 128, 128)
endif
endif
hook = 0
endif
endif
endif
endif
endif
// -----------------------------------------------------
// === BEARISH ROSS HOOK DETECTION ===
// -----------------------------------------------------
if pvt1 <> undefined and pvt4 <> undefined then
// Crossunder: low crosses below pvt1
bearCross = (low < pvt1 and low[1] >= pvt1[1])
if bearCross and hook = 1 then
// pvt0 > pvt1 = correction after low (pullback up)
if pvt0 > pvt1 then
// Validate structure: LL-LH sequence
if pvt1 < pvt3 and pvt0 < pvt2 and pvt2 < pvt4 and pvt3 < pvt2 then
if barindex - idx1 >= prd then
// Search for First Hook between point 4 and point 3
first = barindex - idx4
sec = barindex - idx3
foundHook = 0
//hookBar = 0
for i = first downto sec do
if close[i] < pvt2 and (idx2 - barindex + i) >= dst then
foundHook = 1
//hookBar = i
break
endif
next
if foundHook = 1 then
// --- Draw First Hook line ---
if showPattern then
//drawsegment(barindex - hookBar, pvt2, idx2, pvt2) coloured(128, 128, 128) style(dottedline)
//midFH = round((barindex - hookBar + idx2) / 2)
//drawtext("First Hook", midFH, pvt2 + offset) coloured(128, 128, 128)
endif
// --- Draw Break signal ---
if showBreak then
//drawpoint(barindex, low - offset, 3) coloured(rBear, gBear, bBear)
endif
// --- Draw Ross Hook line ---
if showHook then
//drawsegment(idx3, pvt3, barindex, pvt3) coloured(128, 128, 128) style(dottedline)
//midRH = round((barindex + idx3) / 2)
//drawtext("Ross Hook", midRH, pvt3 + offset) coloured(128, 128, 128)
endif
// --- Draw full pattern ---
if showPattern then
// Second Hook line
//drawsegment(idx1, pvt1, barindex, pvt1) coloured(128, 128, 128) style(dottedline)
//midSH = round((barindex + idx1) / 2)
//drawtext("Second Hook", midSH, pvt1 - offset) coloured(128, 128, 128)
// Pattern points 1-2-3
//drawtext("1", idx4, pvt4 + offset) coloured(128, 128, 128)
//drawtext("2", idx3, pvt3 - offset) coloured(128, 128, 128)
//drawtext("3", idx2, pvt2 + offset) coloured(128, 128, 128)
// Zigzag connecting lines
//drawsegment(idx2, pvt2, idx3, pvt3) coloured(128, 128, 128)
//drawsegment(idx3, pvt3, idx4, pvt4) coloured(128, 128, 128)
endif
endif
hook = 0
endif
endif
endif
endif
endif
// -----------------------------------------------------
// === HOOK RESET ===
// -----------------------------------------------------
// allow new detection when pivot structure changes
if pvt1 <> pvt1[1] then
hook = 1
endif
// -----------------------------------------------------
Cond = 0
IF HLflag[1] THEN
//DrawText("HL",BarIndex[1],high[1]+range[1],sansserif,bold,14) coloured("Cyan")
Cond = 1
ELSiF LHflag[1] THEN
//DrawText("LH",BarIndex[1],low[1]-range[1],sansserif,bold,14) coloured("Fuchsia")
Cond = 2
ENDIF
SCREENER[Cond](Cond AS "1=HL,2=LH")
Sin embargo, en mis pruebas no pude obtener ningún resultado, probablemente también debido a que solo tenía 256 velas disponibles con los screeners.
Buenas. Aquí tienes una versión del indicador y del screener, adaptados a lo que creo que estás buscando.
El problema de fondo es que el indicador original usa pivots de tipo “lookback” (solo mira hacia atrás), por lo que la última etiqueta puede cambiar si el precio sigue moviéndose en la misma dirección. Para resolver esto he reescrito tanto el indicador como el screener usando pivots centrados: el pivot solo se confirma cuando tiene prd barras a cada lado (por defecto 15). Una vez confirmado, la etiqueta ya no cambia.
El indicador tiene dos partes visuales:
– Parte confirmada: zigzag en línea sólida con etiquetas HH (verde), LL (rojo), HL (cyan, negrita) y LH (fucsia, negrita). Estas etiquetas son permanentes.
– Parte provisional: desde el último pivot confirmado hasta el extremo actual, dibujado en naranja punteado con etiqueta con interrogación (HL?, LL?, HH?, LH?). Esta parte sí puede cambiar.
El screener usa exactamente la misma lógica que el indicador y devuelve:
– 1 = nuevo HL confirmado
– 2 = nuevo LH confirmado
Importante: la detección tiene un retraso de prd barras (15 por defecto).
Código Indicador:
//————————————————————————————————//
// PRC_ZigZag SR Confirmed
// version = 1
// 09.03.2026
// Iván González @ www.prorealcode.com
// Sharing ProRealTime knowledge
//————————————————————————————————//
// Centered pivots: confirmed with prd bars on each
// side. Labels are permanent once drawn (no repaint).
// HL and LH are highlighted in bold cyan/fuchsia.
// Provisional (unconfirmed) segment drawn in orange.
//————————————————————————————————//
// --- Inputs ---
//————————————————————————————————//
prd = 15
showSR = 1 //Show Support and Resistance//Boolean
showLabels = 1 //Show pivot labels (HH/HL/LH/LL)//Boolean
showZZ = 1 //Show ZigZag line//Boolean
atrVal = averagetruerange[14](close)
offset = atrVal * 0.5
//————————————————————————————————//
// Centered Pivot Detection
//————————————————————————————————//
ph = 0
pl = 0
if barindex >= 2 * prd then
ph = (high[prd] = highest[2 * prd + 1](high))
pl = (low[prd] = lowest[2 * prd + 1](low))
endif
//————————————————————————————————//
// Direction
//————————————————————————————————//
if ph and pl = 0 then
dir = 1
elsif pl and ph = 0 then
dir = -1
else
dir = dir
endif
dirchanged = (dir <> dir[1])
//————————————————————————————————//
// Build ZigZag Array
//————————————————————————————————//
if ph or pl then
if dirchanged then
if dir = 1 then
t = t + 1
$zigzag[t] = high[prd]
$zigzagidx[t] = barindex - prd
$dir[t] = 1
elsif dir = -1 then
t = t + 1
$zigzag[t] = low[prd]
$zigzagidx[t] = barindex - prd
$dir[t] = -1
endif
else
if dir = 1 and high[prd] > $zigzag[t] then
$zigzag[t] = high[prd]
$zigzagidx[t] = barindex - prd
elsif dir = -1 and low[prd] < $zigzag[t] then
$zigzag[t] = low[prd]
$zigzagidx[t] = barindex - prd
endif
endif
endif
//————————————————————————————————//
// Guard index 0
//————————————————————————————————//
$zigzag[0] = undefined
$zigzagidx[0] = undefined
//————————————————————————————————//
// Draw ZigZag, SR Levels and Labels
//————————————————————————————————//
if islastbarupdate and t >= 2 then
// === CONFIRMED PART ===
// --- Last confirmed segment ---
if showZZ then
drawsegment($zigzagidx[t - 1], $zigzag[t - 1], $zigzagidx[t], $zigzag[t])
endif
// --- SR levels from last two confirmed pivots ---
if showSR then
if $dir[t] = 1 then
drawsegment($zigzagidx[t], $zigzag[t], barindex, $zigzag[t]) style(dottedline, 3) coloured("green")
drawsegment($zigzagidx[t - 1], $zigzag[t - 1], barindex, $zigzag[t - 1]) style(dottedline, 3) coloured("red")
elsif $dir[t] = -1 then
drawsegment($zigzagidx[t], $zigzag[t], barindex, $zigzag[t]) style(dottedline, 3) coloured("red")
drawsegment($zigzagidx[t - 1], $zigzag[t - 1], barindex, $zigzag[t - 1]) style(dottedline, 3) coloured("green")
endif
endif
// --- Label for last confirmed pivot ---
if showLabels and t >= 3 then
if $dir[t] = 1 then
if $zigzag[t] > $zigzag[t - 2] then
drawtext("HH", $zigzagidx[t], $zigzag[t] + offset) coloured("green")
else
drawtext("LH", $zigzagidx[t], $zigzag[t] + offset, sansserif, bold, 12) coloured("fuchsia")
endif
elsif $dir[t] = -1 then
if $zigzag[t] > $zigzag[t - 2] then
drawtext("HL", $zigzagidx[t], $zigzag[t] - offset, sansserif, bold, 12) coloured("cyan")
else
drawtext("LL", $zigzagidx[t], $zigzag[t] - offset) coloured("red")
endif
endif
endif
// --- Dots on last two confirmed pivots ---
drawpoint($zigzagidx[t - 1], $zigzag[t - 1], 2) coloured("blue", 100)
drawpoint($zigzagidx[t], $zigzag[t], 2) coloured("blue", 100)
// --- Draw full confirmed ZigZag history ---
for i = t - 1 downto 3 do
if showZZ then
drawsegment($zigzagidx[i - 1], $zigzag[i - 1], $zigzagidx[i], $zigzag[i])
endif
if showSR and $dir[i] = 1 then
drawsegment($zigzagidx[i], $zigzag[i], $zigzagidx[i + 1], $zigzag[i]) style(dottedline, 3) coloured("green")
drawsegment($zigzagidx[i - 1], $zigzag[i - 1], $zigzagidx[i], $zigzag[i - 1]) style(dottedline, 3) coloured("red")
elsif showSR and $dir[i] = -1 then
drawsegment($zigzagidx[i], $zigzag[i], $zigzagidx[i + 1], $zigzag[i]) style(dottedline, 3) coloured("red")
drawsegment($zigzagidx[i - 1], $zigzag[i - 1], $zigzagidx[i], $zigzag[i - 1]) style(dottedline, 3) coloured("green")
endif
if showLabels then
if $dir[i] = 1 and $zigzag[i] > $zigzag[i - 2] then
drawtext("HH", $zigzagidx[i], $zigzag[i] + offset) coloured("green")
elsif $dir[i] = 1 and $zigzag[i] <= $zigzag[i - 2] then
drawtext("LH", $zigzagidx[i], $zigzag[i] + offset, sansserif, bold, 12) coloured("fuchsia")
elsif $dir[i] = -1 and $zigzag[i] > $zigzag[i - 2] then
drawtext("HL", $zigzagidx[i], $zigzag[i] - offset, sansserif, bold, 12) coloured("cyan")
elsif $dir[i] = -1 and $zigzag[i] <= $zigzag[i - 2] then
drawtext("LL", $zigzagidx[i], $zigzag[i] - offset) coloured("red")
endif
endif
next
// ============================================
// === PROVISIONAL (UNCONFIRMED) SEGMENT ===
// ============================================
// From last confirmed pivot to the provisional
// extreme. Drawn in orange dashed with "?" label.
// This part MAY CHANGE as new bars arrive.
// ============================================
barsBack = barindex - $zigzagidx[t]
if barsBack >= 1 then
if $dir[t] = 1 then
// Last confirmed is HIGH > look for provisional LOW
provBarsAgo = LowestBars[barsBack](low)
provVal = lowest[barsBack](low)
provIdx = barindex - provBarsAgo
if showZZ then
drawsegment($zigzagidx[t], $zigzag[t], provIdx, provVal) coloured("orange") style(dottedline, 2)
endif
if showSR then
drawsegment(provIdx, provVal, barindex, provVal) style(dottedline, 2) coloured("orange")
endif
if showLabels and t >= 3 then
if provVal > $zigzag[t - 1] then
drawtext("HL?", provIdx, provVal - offset) coloured("orange")
else
drawtext("LL?", provIdx, provVal - offset) coloured("orange")
endif
endif
drawpoint(provIdx, provVal, 2) coloured("orange", 100)
elsif $dir[t] = -1 then
// Last confirmed is LOW > look for provisional HIGH
provBarsAgo = HighestBars[barsBack](high)
provVal = highest[barsBack](high)
provIdx = barindex - provBarsAgo
if showZZ then
drawsegment($zigzagidx[t], $zigzag[t], provIdx, provVal) coloured("orange") style(dottedline, 2)
endif
if showSR then
drawsegment(provIdx, provVal, barindex, provVal) style(dottedline, 2) coloured("orange")
endif
if showLabels and t >= 3 then
if provVal < $zigzag[t - 1] then
drawtext("LH?", provIdx, provVal + offset) coloured("orange")
else
drawtext("HH?", provIdx, provVal + offset) coloured("orange")
endif
endif
drawpoint(provIdx, provVal, 2) coloured("orange", 100)
endif
endif
endif
//————————————————————————————————//
return
Código Screener
//————————————————————————————————//
// PRC_ZigZag SR Confirmed - Screener
// version = 1
// 09.03.2026
// Iván González @ www.prorealcode.com
// Sharing ProRealTime knowledge
//————————————————————————————————//
// Same zigzag logic as the indicator.
// Returns: 1 = HL confirmed, 2 = LH confirmed
//————————————————————————————————//
// --- Input ---
prd = 15
//————————————————————————————————//
// Centered Pivot Detection
//————————————————————————————————//
ph = 0
pl = 0
if barindex >= 2 * prd then
ph = (high[prd] = highest[2 * prd + 1](high))
pl = (low[prd] = lowest[2 * prd + 1](low))
endif
//————————————————————————————————//
// Direction
//————————————————————————————————//
if ph and pl = 0 then
dir = 1
elsif pl and ph = 0 then
dir = -1
else
dir = dir
endif
dirchanged = (dir <> dir[1])
//————————————————————————————————//
// Build ZigZag Array (same as indicator)
//————————————————————————————————//
if ph or pl then
if dirchanged then
if dir = 1 then
t = t + 1
$zigzag[t] = high[prd]
$dir[t] = 1
elsif dir = -1 then
t = t + 1
$zigzag[t] = low[prd]
$dir[t] = -1
endif
else
if dir = 1 and high[prd] > $zigzag[t] then
$zigzag[t] = high[prd]
elsif dir = -1 and low[prd] < $zigzag[t] then
$zigzag[t] = low[prd]
endif
endif
endif
$zigzag[0] = undefined
//————————————————————————————————//
// Detect new confirmed pivot and classify
//————————————————————————————————//
myResult = 0
newPivot = (t > t[1])
if newPivot and t >= 3 then
if $dir[t] = -1 and $zigzag[t] > $zigzag[t - 2] then
// HL: confirmed low is higher than previous low
myResult = 1
elsif $dir[t] = 1 and $zigzag[t] < $zigzag[t - 2] then
// LH: confirmed high is lower than previous high
myResult = 2
endif
endif
SCREENER[myResult](myResult AS "1=HL 2=LH")
Buenas tardes Iván, gracias por tu trabajo, he estado testeando el indicador modificado y todo parecía ir genial, pero comparándolo con el indicador original, este nuevo es más lento en el momento de producirse el cambio fijo de HL o LH, el indicador original ya ha impreso el HL cuando el modificado aún tardará unas cuantas vela nuevas hasta hacerlo, y la verdad es que interesa que avise cuantas más antelación mejor, no sé si habría que modificar algún parámetro para hacerlo idéntico al original, gracias por todo
Screener de ZigZag and SR
This topic contains 4 replies,
has 3 voices, and was last updated by NicoGB67
7 hours, 36 minutes ago.
| Forum: | Soporte Plataforma: Gráficos, Datos y Brokers |
| Language: | Spanish |
| Started: | 03/07/2026 |
| Status: | Active |
| Attachments: | 2 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.