# Bar count btwn zigzag highs and lows

#### wlbsr

##### New member
I have a simple zigzag indicator. rather than the bar number, I would like to have the number of bars since the last high/low

Code:
``````def zz = reference ZigZagHighLow(close, close, 5,0, 0, 0);

plot zzp=zz;
zzp.EnableApproximation();

def barNumber  = barNumber();

Solution
I have a simple zigzag indicator. rather than the bar number, I would like to have the number of bars since the last high/low

Code:
``````def zz = reference ZigZagHighLow(close, close, 5,0, 0, 0);

plot zzp=zz;
zzp.EnableApproximation();

def barNumber  = barNumber();

Try this

Code:
``````input showbubble_bars_since = yes;
def zz = reference ZigZagHighLow(close, close, 5, 0, 0, 0);

plot zzp = zz;
zzp.EnableApproximation();

def barNumber  = BarNumber();
def zzbar  = if !IsNaN(zz) then barNumber else zzbar[1];
def zzbar1 = if zzbar != zzbar[1] then zzbar[1] else zzbar1[1];
input test = no;
AddLabel(test, zzbar + " " + zzbar1);
AddChartBubble(test, close, "BN: " + barNumber )...``````
I have a simple zigzag indicator. rather than the bar number, I would like to have the number of bars since the last high/low

Code:
``````def zz = reference ZigZagHighLow(close, close, 5,0, 0, 0);

plot zzp=zz;
zzp.EnableApproximation();

def barNumber  = barNumber();

Try this

Code:
``````input showbubble_bars_since = yes;
def zz = reference ZigZagHighLow(close, close, 5, 0, 0, 0);

plot zzp = zz;
zzp.EnableApproximation();

def barNumber  = BarNumber();
def zzbar  = if !IsNaN(zz) then barNumber else zzbar[1];
def zzbar1 = if zzbar != zzbar[1] then zzbar[1] else zzbar1[1];
input test = no;
AddLabel(test, zzbar + " " + zzbar1);
AddChartBubble(test, close, "BN: " + barNumber );
AddChartBubble(showbubble_bars_since and zz, close, "# Bars\nSince\nLast: " + AbsValue(zzbar1 - zzbar), Color.WHITE, if close > open then yes else no);``````

87k+ Posts
211 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?