# peaks_valley_diag_lines_00
#------------------------
#https://usethinkscript.com/threads/zigzag-high-low-with-supply-demand-zones-for-thinkorswim.172/#post-7048
# define swing low points , robert payne
# modifified by halcyonguy to ignore last bar
#------------------------
def bn = BarNumber();
def na = double.nan;
input length = 7;
def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def offset = Min(length - 1, lastBar - bn);
input ignore_last_bar = yes;
def ignorelast = if (ignore_last_bar and bn == lastbar) then 0 else 1;
def peak = ignorelast and high > highest(high[1], length - 1) and high == GetValue(highest(high, length), -offset);
def valley = ignorelast and low < Lowest(low[1], length - 1) and low == GetValue(Lowest(low, length), -offset);
#-------------------------------------
input show_dots_on_peaks_valleys = yes;
def vert = 0.002;
plot z1 = if show_dots_on_peaks_valleys and peak then high*(1+vert) else na;
z1.SetPaintingStrategy(PaintingStrategy.POINTS);
z1.SetDefaultColor(Color.cyan);
z1.setlineweight(3);
z1.hidebubble();
plot z2 = if show_dots_on_peaks_valleys and valley then low*(1-vert) else na;
z2.SetPaintingStrategy(PaintingStrategy.POINTS);
z2.SetDefaultColor(Color.cyan);
z2.setlineweight(3);
z2.hidebubble();
plot zp = if peak then high else double.nan;
zp.EnableApproximation();
plot zv = if valley then low else double.nan;
zv.EnableApproximation();
#