{ Downloaded From https://www.WiseStockTrader.com }
 { Data bar statistics v1.0 }
{ Display in own window, then Zoom & Reset }
{ Irregular yearly data bar count indicates
missing data and/or illiquid chart }
{ (c) Copyright 2005 Jose Silva
For personal use only
http://www.metastocktools.com }

{ User inputs }
display:=Input("Count: [1]Year's bars, [2]Years, [3]Bars",1,3,1);
type:=Input("Stats: [1]Individual years', [2]Avg/Total",1,2,1);

{ First year of loaded chart data }
year1:=ValueWhen(1,Cum(1)=1,Year());
year1flag:=Year()=year1;

{ Yearly bar stats }
yStart:=Year()<>Ref(Year(),-1);
yearStart:=yStart OR Cum(IsDefined(yStart))=1;
yearCount:=Cum(yearStart)-1;
yearBars:=BarsSince(yearStart)+1+year1flag;
YearStats:=If(display=1,yearBars,
If(display=2,yearCount,Cum(1)));

{ Total/Avg bar stats }
barCount:=LastValue(Cum(1));
yearCount:=LastValue(Year())-year1;
yearlyAvgBars:=Int(barCount/yearCount+.5);
TotalStats:=If(display=1,yearlyAvgBars,
If(display=2,yearCount,barCount));

{ Plot in own window below price chart }
If(type=1,YearStats,TotalStats)