# Count number of bars between lows

B

#### british43

##### New member

Code:
``````def peak = high > Highest(high, 5) and high > Highest(high[-5], 5);

# count the number of bars since the last peak
def count = if peak then 1 else count + 1;

# mark each peak with a down arrow
plot peakArrow = peak;
peakArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

# show the number of bars (the count) since the last peak
AddChartBubble(peak, high + 1, count, Color.WHITE);``````

B

#### british43

##### New member
I'm not sure what I'm doing wrong but I'm trying to look for how many bull or bear bars exist within a timeframe.

Code:
``````#price as % of H-L range with coloring above 50% and below 25%
input price = close;
input lenght = 5;
def RPR = round((price – low) / (high – low) *100);

plot Bull_Trend_Bar= RPR > 50;
plot Bear_Trend_Bar= RPR < 25;

#def countup = if Bull_Trend_Bar == lenght
#then BarNumber()
# else countup;

#AddLabel(1, "Count = " + countup, Color.CYAN);

# count the number of bars since the last peak
def count = if RPR then 1 else count + 1;

#def count1 = if Bull_Trend_Bar then 1 else count1 + 1;

addlabel(yes, concat("Bull Trend Bar: " + RPR, "%"), if RPR > 50 then color.green else color.current);

addlabel(yes, concat("Bear Trend Bar: " + RPR, "%"), if RPR < 25 then color.red else color.current);

addlabel(yes, concat("Bull Trend Bar: " +  Bull_Trend_Bar, ""), if  Bull_Trend_Bar is true then color.green else color.current);

addlabel(yes, concat("Bear Trend Bar: " +  Bear_Trend_Bar, ""), if  Bear_Trend_Bar is true then color.red else color.current);

#plot x =1;``````