xClose = (open+high+low+close)/4
IF BarIndex=0 THEN
xOpen = open
xHigh = high
xLow = low
ELSe
xOpen = (xOpen[1] + xClose[1])/2
xHigh = Max(Max(high, xOpen), xClose)
xLow = Min(Min(low, xOpen), xClose)
ENDIF
green = xClose>xOpen
red = not green
body = Abs(xclose-xopen)
sup = (xhigh-max(xopen,xclose))/body*100
inf = (min(xopen,xclose)-xlow)/body*100
if green and red[1] then
start=barindex
endif
if barindex-start=2 then
c0 = green and inf<20 and sup<50
c1 = green[1] and inf[1]<20 and sup[1]<50
c2 = green[2] and inf[2]<30 and sup[1]<50
else
c0=0
c1=0
c2=0
endif
if red and green[1] then
start=barindex
endif
if barindex-start=2 then
c3 = red and inf<20 and sup<50
c4 = red[1] and inf[1]<20 and sup[1]<50
c5 = red[2] and inf[2]<30 and sup[1]<50
else
c3=0
c4=0
c5=0
endif
return (c0 and c1 and c2) coloured(0,255,0) style(histogram), (c3 and c4 and c5) coloured(255,0,0) style(histogram)