zigzag indicator enter points code on pine script

Viewed 40

I am new in pine-script and I have a question about how to get enter point signal of zigzag indicator in trading view. I appreciate if someone can help me on this issue. this code shows the last highest high and lowest low. but it is repainting by moving the price, till another line happen. here like it mentioned in photos i want to use this indicator to show me some signals.

1.photo

2.photo

here is the version5 pines script code thanks

indicator('ZigZag', 'ZigZag', true, format.price, max_labels_count=51, max_lines_count=500)
Depth = input.int(27, 'Depth', minval=1, step=1)
Deviation = input.int(1, 'Deviation', minval=1, step=1)
Backstep = input.int(2, 'Backstep', minval=2, step=1)
line_thick = input.int(2, 'Line Thickness', minval=1, maxval=4)
upcolor = input(color.lime, 'Bull Color')
dncolor = input(color.red, 'Bear Color')
repaint = input(true, 'Repaint Levels')
var last_h = 1
last_h += 1
var last_l = 1
last_l += 1
var lw = 1
var hg = 1
lw += 1
hg += 1
p_lw = -ta.lowestbars(Depth)
p_hg = -ta.highestbars(Depth)
lowing = lw == p_lw or low - low[p_lw] > Deviation * syminfo.mintick
highing = hg == p_hg or high[p_hg] - high > Deviation * syminfo.mintick
lh = ta.barssince(not highing[1])
ll = ta.barssince(not lowing[1])
down = ta.barssince(not(lh > ll)) >= Backstep
lower = low[lw] > low[p_lw]
higher = high[hg] < high[p_hg]
if lw != p_lw and (not down[1] or lower)
    lw := p_lw < hg ? p_lw : 0
    lw
if hg != p_hg and (down[1] or higher)
    hg := p_hg < lw ? p_hg : 0
    hg
line zz = na
label point = na
x1 = down ? lw : hg
y1 = down ? low[lw] : high[hg]
if down == down[1]
    if repaint
        label.delete(point[1])
        line.delete(zz[1])
    down
if down != down[1]
    if down
        last_h := hg
        last_h
    else
        last_l := lw
        last_l
    if not repaint
        nx = down ? last_h : last_l
        zz := line.new(bar_index - nx, down ? high[nx] : low[nx], bar_index - (down ? last_l : last_h), down ? low[last_l] : high[last_h], width=line_thick, color=down ? upcolor : dncolor)
        point := label.new(bar_index - nx, down ? high[nx] : low[nx], down ? high[nx] > high[last_h[1]] ? 'HH' : 'LH' : low[nx] < low[last_l[1]] ? 'LL' : 'HL', style=down ? label.style_label_down : label.style_label_up, size=size.tiny, color=down ? dncolor : upcolor, textcolor=color.black, tooltip=down ? high[nx] > high[last_h[1]] ? 'Higher High' : 'Lower High' : low[nx] < low[last_l[1]] ? 'Lower Low' : 'Higher Low')
        point
    down
if repaint
    zz := line.new(bar_index - (down ? last_h : last_l), down ? high[last_h] : low[last_l], bar_index - x1, y1, width=line_thick, color=down ? dncolor : upcolor)
    point := label.new(bar_index - x1, y1, down ? low[x1] < low[last_l] ? 'LL' : 'HL' : high[x1] > high[last_h] ? 'HH' : 'LH', style=down ? label.style_label_up : label.style_label_down, size=size.tiny, color=down ? upcolor : dncolor, textcolor=color.black, tooltip=down ? low[x1] < low[last_l] ? 'Lower Low' : 'Higher Low' : high[x1] > high[last_h] ? 'Higher High' : 'Lower High')
    point
bear = down
alertcondition(bear != bear[1], 'Direction Changed', 'Zigzag on {{ticker}} direction changed at {{time}}')
alertcondition(bear != bear[1] and not bear, 'Bullish Direction', 'Zigzag on {{ticker}} bullish direction at {{time}}')
alertcondition(bear != bear[1] and bear, 'Bearish Direction', 'Zigzag on {{ticker}} bearish direction at {{time}}')
0 Answers
Related