def H = high;
def L = low;
def C = close;
def O = open;
def insidebar = (H <= H[1] and L >= L[1]);
#def insidebar = (H < H[1] and L > L[1]) or (H == H[1] and L > L[1]) or (H < H[1] and L == L[1]) or (H == H[1] and L == L[1]);
def outsidebar = H > H[1] and L < L[1];
def insidebarup = insidebar and O < C;
def twoup = H > H[1] and L >= L[1];
def neartwoup = c > (H[1]*.999) and L >= L[1];
def outsidebarup = outsidebar and O < C;
def insidebardn = insidebar and O > C;
def twodown = H <= H[1] and L < L[1];
def neartwodown = H <= H[1] and c < (L[1]/.999);
def outsidebardn = outsidebar and O > C;
input barsago = 100;
def WithinBars = BarNumber() > HighestAll(BarNumber()) - barsago - 1; #can delete - 1
def count =
if withinBars ### here ###
and twodown[2]
and insidebar[1]
and high > high[1]
then count[1] + 1
else count[1];
AddLabel (yes, " BUY COUNT: " + count + " ", Color.cyan );
### delete this junk if you want
def x = if count != count[1] then count else double.nan;;
plot y = x;
plot "I cant see this color, ignore this" = double.nan;
plot z = x;
y.setpaintingStrategy(paintingStrategy.VALUES_BELOW);
y.setlineWeight(5);
z.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_DOWN);
z.setlineWeight(5);
plot a = BarNumber() == HighestAll(BarNumber()) - barsago - 1; #can delete - 1
a.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);
a.setlineWeight(5);