This indicator displays the number of bars in your trend.  The below code is for the CCI, but you could add any indicator into the code where price is above or below a certain level.  For example, in the picture there is a Hull Moving Average and RSI as well as the CCI shown.  When the trend is over 10 bars, the color changes indicating that the trend could be getting exhausted.  Below is a 4 hour chart of NQ.  When all three of these reset at the exact same bar, that indicates a strong new trend.  The labels show you how many bars the trend is currently in.  This could also help in analyzing the average size of past trend lengths.
		
		
	
	
		 
	
	
	
	
	
	
		
	
		
			
		
		
	
				
			
		Code:
	
	#==============================
# CCI Trend Duration (Lower Study)
# Assembled by Chewie
#==============================
declare lower;
#-----------------------------------
# CCI
#-----------------------------------
input length = 14;
input price = close;
input cciMid = 0;
# --- CCI Levels ---
def mean = Average(price, length);
def dev = Average(AbsValue(price - mean), length);
def bandMid   = mean + cciMid   * 0.015 * dev;
def CCI  = bandMid;
#-----------------------------------------------
# Trend direction detection
#-----------------------------------------------
def rising = close > CCI;
def falling = close < CCI;
# Boolean trend signal (1 = up, 0 = down)
def trendUp = if rising then 1 else if falling then 0 else trendUp[1];
# Detect when trend changes
def trendChange = trendUp[1] != trendUp;
#-----------------------------------
# Trend duration counting
#-----------------------------------
def trendCount = if trendChange then 1 else trendCount[1] + 1;
#-----------------------------------
# Plot Trend Durations
#-----------------------------------
plot BullTrendLength = if trendUp then trendCount else Double.NaN;
BullTrendLength.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
BullTrendLength.SetDefaultColor(Color.GREEN);
BullTrendLength.SetLineWeight(2);
plot BearTrendLength = if !trendUp then trendCount else Double.NaN;
BearTrendLength.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
BearTrendLength.SetDefaultColor(Color.red);
BearTrendLength.SetLineWeight(2);
Bulltrendlength.AssignValueColor(if bulltrendlength >= 10 then Color.cyan else color.current);
Beartrendlength.AssignValueColor(if beartrendlength >= 10 then Color.magenta else color.current);
plot signal = 10;
signal.setdefaultColor(color.cyan);
#-----------------------------------
# Labels for quick reference
#-----------------------------------
AddLabel(yes, "CCI_Uptrend(bars): " + AsText(BullTrendLength), Color.GREEN);
AddLabel(yes, "Downtrend(bars): " + AsText(BearTrendLength), Color.red); 
				 
						 
 
		 
 
		 
 
		 
 
		 
 
		