# Hide vertical line

#### SJP07

##### Member
Hi everyone,

I created a study that plots a vertical line whenever there is a ZigZag reversal. Is there a way to only show the most recent vertical line and hide all the vertical lines that occurred before it?

Solution
@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.
@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.

@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_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);

Hi everyone,

I created a study that plots a vertical line whenever there is a ZigZag reversal. Is there a way to only show the most recent vertical line and hide all the vertical lines that occurred before it?

Here is an example of one way to do it.

Ruby:
``````def cond = if close > open then BarNumber() else cond[1];
AddVerticalLine(BarNumber() == HighestAll(cond), "", stroke = Curve.FIRM);``````

Here is an example of one way to do it.

Ruby:
``````input show_vertical_line = yes;
#AddVerticalLine((Up_Trend && show_vertical_line), "Bullish", Color.Dark_Green, Curve.FIRM);
#AddVerticalLine((Down_Trend && show_vertical_line), "Bearish", Color.Dark_Red, Curve.FIRM);

def cond = if Up_Trend or Down_Trend then BarNumber() else cond[1];
AddVerticalLine(show_vertical_line and BarNumber() == HighestAll(cond), "", if Up_Trend then Color.GREEN else Color.RED, stroke = Curve.FIRM);``````

@SJP07
@SleepyZ s way is better.

Code:
``````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_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);

#################################################################################
#################################################################################
def UpTrendCount = if Up_Trend then UpTrendCount[1] + 1 else UpTrendCount[1];
def DnTrendCount = if Down_Trend then DnTrendCount[1] + 1 else DnTrendCount[1];
def LastUpTrendCount = fold lutc=0 to AbsValue(BarNumber()) while !IsNaN(GetValue(close, -lutc)) do GetValue(UpTrendCount, -lutc);
def LastDnTrendCount = fold ldtc=0 to AbsValue(BarNumber()) while !IsNaN(GetValue(close, -ldtc)) do GetValue(UpTrendCount, -ldtc);

def ShowUpTrendVerticalLine = UpTrendCount == LastUpTrendCount;
def ShowDnTrendVerticalLine = DnTrendCount == LastDnTrendCount;
#################################################################################
#################################################################################

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;

Wow - thanks both of you! Is there a way to show the last line for Up_trend and Down_Trend? The current code only shows the last line.

@SJP07
Mine shows both.
I think I got it to work. Thanks again! Using the zig zag on charts like Amazon and Tesla is too messy. This helps a lot.

87k+ Posts
373 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?