here is something to experiment with,
i wasn't seeing many triggers with all 6 rules, so i had it draw dots if more than 4 rules happened
draws the rule count if 4 or more,
colored dots , if 4,5,6 rules
draws a horizontal line for a buy level if 4+ rules happen
draw arrow when all 6 rules happen
draws things for long and short trades
doesn't include stop or target
Code:
#ema_2bar_pattern
#https://usethinkscript.com/threads/8ema-candlestick-pattern.17736/
#8ema candlestick pattern
# Plot the EMA8
#===========================
#LONG trade:
#===========================
#EMA8 is rising
#Red candle
#then a green candle that,
#..has a Lower low and a lower high,
#..closes within the body of the red candle.
#..green candle must close above 8 EMA.
#..a yellow warn up arrow under green candle
#entry:
#1 tick above green bar
#(or as long as EMA is rising)
#stop:
#20 to 35 points (based on bar before entry)
#target:
#35 points or 1:1 , whichever is less
#===========================
#SHORT:
#===========================
#EMA8 is falling
#Green candle
#then a red candle that,
#..has a higher high and a higher low,
#..closes within the body of the green candle.
#..red candle must close below 8EMA.
#..a yellow warn down arrow above red candle
#entry:
#1 tick below red bar
#(or as long as EMA is falling)
#stop:
#20 to 35 points (based on bar before entry)
#target:
#35 points or 1:1 , whichever is less
#===========================
def na = double.nan;
def bn = barnumber();
def data = close;
def t = tickvalue();
def y = 0.002;
input minqty = 4;
#input minqty = 5;
input show_warn_dots = yes;
input warn_dots_to_show = { default "4" , "5" , "6" };
input avg1_type = AverageType.exponential;
#input avg1_type = AverageType.Simple;
input avg1_length = 8;
def avg1 = MovingAverage(avg1_type, data, avg1_length );
input show_average_lines = yes;
plot zavg1 = if show_average_lines then avg1 else na;
zavg1.SetDefaultColor(Color.cyan);
zavg1.setlineweight(1);
zavg1.hidebubble();
def grn = close > open;
def red = close < open;
def redgrn = red[1] and grn;
def grnred = grn[1] and red;
def bodytop = max(open, close);
def bodybot = min(open, close);
# buy--------------- red-green
def b1 = avg1 > avg1[1];
def b2 = red[1];
def b3 = grn;
#def b4 = low < low[1] and high < high[1];
def b4 = low < low[1];
def b5 = close > bodybot[1] and close < bodytop[1];
def b6 = close > avg1;
def warnb = b1 and b2 and b3 and b4 and b5 and b6;
def b_cnt = b1 + b2 + b3 + b4 + b5 + b6;
# optional b5
def wb = (redgrn and b_cnt >= minqty);
def long_open_level = if wb then (high + t)
else if wb[1] then (high[1] + t)
else if wb[2] then (high[2] + t)
else na;
plot zlonglvl = long_open_level;
zlonglvl.SetDefaultColor(Color.cyan);
zlonglvl.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#plot zupwarn = if warn then low*(1-y) else na;
plot zupwarn = if (show_warn_dots and redgrn and b_cnt >= minqty) then low*(1-y) else na;
zupwarn.SetPaintingStrategy(PaintingStrategy.points);
#zupwarn.SetDefaultColor(Color.yellow);
zupwarn.AssignValueColor(if b_cnt == 6 then color.green else if (redgrn and b_cnt == 5) then color.cyan else if (redgrn and b_cnt == 4) then color.yellow else color.gray);
zupwarn.setlineweight(4);
zupwarn.hidebubble();
plot zup = if (b_cnt == 6) then low*(1-(2*y)) else na;
zup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zup.SetDefaultColor(Color.white);
zup.setlineweight(4);
zup.hidebubble();
plot zv1 = if (redgrn and b_cnt >= minqty) then b_cnt else na;
zv1.SetPaintingStrategy(PaintingStrategy.VALUES_below);
zv1.SetDefaultColor(Color.white);
input test1 = no;
addchartbubble(test1, low,
b1 + "\n" +
b2 + "\n" +
b3 + "\n" +
b4 + "\n" +
b5 + "\n" +
b6 + "\n"
, (if b_cnt == 6 then color.green else if (redgrn and b_cnt >= minqty) then color.yellow else color.gray), no);
# sell --------------- green-red
def s1 = avg1 < avg1[1];
def s2 = grn[1];
def s3 = red;
def s4 = low > low[1] and high > high[1];
def s5 = close > bodybot[1] and close < bodytop[1];
def s6 = close < avg1;
def warns = s1 and s2 and s3 and s4 and s5 and s6;
def s_cnt = s1 + s2 + s3 + s4 + s5 + s6;
# optional s5
def ws = (grnred and s_cnt >= minqty);
def short_open_level = if ws then (low - t)
else if ws[1] then (low[1] - t)
else if ws[2] then (low[2] - t)
else na;
plot zshortlvl = short_open_level;
zshortlvl.SetDefaultColor(Color.magenta);
zshortlvl.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot zdwnwarn = if (show_warn_dots and grnred and s_cnt >= minqty) then high*(1+y) else na;
zdwnwarn.SetPaintingStrategy(PaintingStrategy.points);
#zdwnwarn.SetDefaultColor(Color.yellow);
zdwnwarn.AssignValueColor(if s_cnt == 6 then color.red else if (grnred and s_cnt == 5) then color.magenta else if (grnred and s_cnt == 4) then color.yellow else color.gray);
zdwnwarn.setlineweight(4);
zdwnwarn.hidebubble();
plot zdwn = if (s_cnt == 6) then high*(1+(2*y)) else na;
zdwn.SetPaintingStrategy(PaintingStrategy.ARROW_down);
zdwn.SetDefaultColor(Color.white);
zdwn.setlineweight(4);
zdwn.hidebubble();
plot zv2 = if (grnred and s_cnt >= minqty) then s_cnt else na;
zv2.SetPaintingStrategy(PaintingStrategy.VALUES_above);
zv2.SetDefaultColor(Color.white);
input test2 = no;
addchartbubble(test2, low,
s1 + "\n" +
s2 + "\n" +
s3 + "\n" +
s4 + "\n" +
s5 + "\n" +
s6 + "\n"
, (if s_cnt == 6 then color.green else if (grnred and s_cnt >= minqty) then color.yellow else color.gray), no);
#