@SJP07
Use a counter to assign a number to each vertical line.
Next, use a fold to send the counter value of the last bar back to the the previous counter value.
Then just add a hide condition in the plot of the vertical line to compare the two values and only show if they are equal.
I wish I knew I understand what you meant lol. Here's my code. Do you mind incorporating your suggestions?
input price = close;
input reversalAmount = 1.0;
input showBubbles = no;
input showLabel = no;
Assert(reversalAmount > 0, "'reversal amount' should be positive: " + reversalAmount);
plot "ZZ$" = reference ZigZagHighLow(price, price, 0, reversalAmount, 1, 0);
"ZZ$".Hide();
def zzSave = if !IsNaN("ZZ$") then price else GetValue(zzSave, 1);
def chg = price - GetValue(zzSave, 1);
def isUp = chg >= 0;
def isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue("ZZ$", 1)) and GetValue(isConf, 1));
"ZZ$".EnableApproximation();
"ZZ$".DefineColor("Up Trend", Color.UPTICK);
"ZZ$".DefineColor("Down Trend", Color.DOWNTICK);
"ZZ$".DefineColor("Undefined", Color.DARK_ORANGE);
"ZZ$".AssignValueColor(if !isConf then "ZZ$".Color("Undefined") else if isUp then "ZZ$".Color("Up Trend") else "ZZ$".Color("Down Trend"));
DefineGlobalColor("Unconfirmed", Color.DARK_ORANGE);
DefineGlobalColor("Up", Color.UPTICK);
DefineGlobalColor("Down", Color.DOWNTICK);
def barNumber = BarNumber();
AddChartBubble(showBubbles and !IsNaN("ZZ$") and barNumber != 1, price, chg, if !isConf then GlobalColor("Unconfirmed") else if isUp then GlobalColor("Up") else GlobalColor("Down"), isUp);
AddLabel(showLabel and barNumber != 1, (if isConf then "Confirmed " else "Unconfirmed ") + "ZigZag: " + chg, if !isConf then GlobalColor("Unconfirmed") else if isUp then GlobalColor("Up") else GlobalColor("Down"));
################################################################################
def Up_Trend = isUp[1] is false && isUp is true;
def Down_Trend = isUp[1] is true && isUp is false;
Plot ZZ_Buy = Up_Trend;
ZZ_Buy.Hide();
Plot ZZ_Sell = Down_Trend;
ZZ_Sell.Hide();
AddLabel(yes, if isUp is true then "Bullish" else "", Color.UPTICK);
AddLabel(yes, if isUp is false then "Bearish" else "", Color.DOWNTICK);
input show_Chart_Bubble = no;
AddChartBubble(Up_Trend && show_Chart_Bubble, low, "ZZ", Color.UPTICK, no);
AddChartBubble(Down_Trend && show_Chart_Bubble, high, "ZZ", Color.DOWNTICK, yes);
input show_vertical_line = no;
AddVerticalLine((Up_Trend && show_vertical_line), "Bullish", Color.Dark_Green, Curve.FIRM);
AddVerticalLine((Down_Trend && show_vertical_line), "Bearish", Color.Dark_Red, Curve.FIRM);