#green3_red_grn
#https://usethinkscript.com/threads/the-red-knock-out.17838/
#The Red Knock Out
#felz5628 2/14
#Can someone write a script for the following setup:
#1. Three or more consecutive green up day candles
#2. Red candle immediately following the three or more green up day candle, with a smaller body than each previous green candles.
#3. Green candle that takes out the high of the previous red candle.
def na = double.nan;
def bn = barnumber();
input greenhavetobeup = yes;
input min_green = 3;
def grn = close > open;
def red = close < open;
def grncnt = sum(grn, min_green);
def isgrncnt = grncnt >= min_green;
def b = bodyheight();
def grnbodymin = if grn and red[1] then b
else if grn and grn[1] then min(b, b[1])
else 0;
def isredsmall = if red and grn[1] and isgrncnt[1] and b <= grnbodymin[1] then 1 else 0;
def redgrn = if isredsmall[1] and high >= high[1] and grn then 1 else 0;
plot zup = if redgrn then low*0.999 else na;
zup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zup.SetDefaultColor(Color.cyan);
zup.setlineweight(4);
zup.hidebubble();
addchartbubble(0, low*0.999,
grn + " G\n" +
red + " R\n" +
b + " b\n" +
grncnt + " C\n" +
isgrncnt + " iG\n" +
grnbodymin + " min\n" +
isredsmall + " sml\n" +
redgrn + " rg\n"
, color.yellow, no);
addchartbubble(0, low*0.999,
#grn + " G\n" +
#red + " R\n" +
#b + " b\n" +
#grncnt + " C\n" +
isgrncnt + " iG\n" +
grnbodymin + " min\n" +
isredsmall + " sml\n" +
redgrn + " rg\n"
, color.yellow, no);
#