# 8ema candlestick pattern

#### TDTOS

##### Member
There is a strategy that seems to produce good results and seeing if it can be made here. Attached is an infographic explaining the rules but here is a summary.

Plot the 8EMA

For long:
1. Red candle and then a green candle that has a Lower low and a lower high but closes within the body of the red candle. Green candle must close above 8 EMA. A repainting arrow would be excellent during the formation of the candle which would stay permanent when the candle closes with conditions met.

For short:
1. Green candle and then a red candle that has a higher high and a higher low but closes within the body of the green candle. Red candle must close below 8EMA. A repainting arrow would be excellent during the formation of the candle which would stay permanent when the candle closes with conditions met.

Thank you!

#### Attachments

121.5 KB · Views: 175
Solution
There is a strategy that seems to produce good results and seeing if it can be made here. Attached is an infographic explaining the rules but here is a summary.

Plot the 8EMA

For long:
1. Red candle and then a green candle that has a Lower low and a lower high but closes within the body of the red candle. Green candle must close above 8 EMA. A repainting arrow would be excellent during the formation of the candle which would stay permanent when the candle closes with conditions met.

For short:
1. Green candle and then a red candle that has a higher high and a higher low but closes within the body of the green candle. Red candle must close below 8EMA. A repainting arrow would be excellent during the formation of the...
There is a strategy that seems to produce good results and seeing if it can be made here. Attached is an infographic explaining the rules but here is a summary.

Plot the 8EMA

For long:
1. Red candle and then a green candle that has a Lower low and a lower high but closes within the body of the red candle. Green candle must close above 8 EMA. A repainting arrow would be excellent during the formation of the candle which would stay permanent when the candle closes with conditions met.

For short:
1. Green candle and then a red candle that has a higher high and a higher low but closes within the body of the green candle. Red candle must close below 8EMA. A repainting arrow would be excellent during the formation of the candle which would stay permanent when the candle closes with conditions met.

Thank you!

your post mentions 2 price parameters, ( low and high)
green candle that has a Lower low and a lower high

and the image mentions only one, (low)
green candle that has a Lower low

There is a strategy that seems to produce good results and seeing if it can be made here. Attached is an infographic explaining the rules but here is a summary.

Plot the 8EMA

For long:
1. Red candle and then a green candle that has a Lower low and a lower high but closes within the body of the red candle. Green candle must close above 8 EMA. A repainting arrow would be excellent during the formation of the candle which would stay permanent when the candle closes with conditions met.

For short:
1. Green candle and then a red candle that has a higher high and a higher low but closes within the body of the green candle. Red candle must close below 8EMA. A repainting arrow would be excellent during the formation of the candle which would stay permanent when the candle closes with conditions met.

Thank you!

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

#8ema candlestick pattern

# Plot the EMA8

#===========================
#===========================

#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);

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;
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;
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);

#

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

#8ema candlestick pattern

# Plot the EMA8

#===========================
#===========================

#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);

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;
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;
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);

#

Thank you very much! I appreciate it!

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

#8ema candlestick pattern

# Plot the EMA8

#===========================
#===========================

#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);

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;
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;
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);

#

First of all, excellent work, thank you for sharing this! Also, I have a few questions on your thinkscript, one of the things I noticed is that the script doesn't appear to have an option to turn on or off the first rule which is the ema trend up or down, That would be really helpful, sometimes it doesn't identify a valid setup when the ema is trending slightly opposite or flat. Secondly, the script properly identifies the short setups when the second candle makes a new high but not a new low, but it does not work for the long setup ruling out those candles that also make a new high, i.e. the second green candle has a lower low, but also has a 1 tick or more (i.e. 0.25) higher high than the previous red candle. (As I was writing this I realized the script you posted didn't have the full "def = b4..." line complete, it should include: "and high < high[1]" like so: i basically answered my second question
#def b4 = low < low[1] and high < high[1];
def b4 = low < low[1] and high , high[1];
Third and finally, I am looking for a way to incorporate a true or false or or other type of script/statement which will allow me to add the study into an alert condition thereby allowing me to be notified of when a setup occurs during market hours, where all the conditions are met with exception of the ema/avg trend direction. Thank you for your help with this script!

#### Attachments

• Screenshot 2024-04-22 231448.png
100.4 KB · Views: 92
• Screenshot 2024-04-22 231608.png
96 KB · Views: 95
MTF 8EMA / Price % Label Questions 1
inside days with closes above the 8ema Questions 1
Candlestick body to range percentage Questions 1
Long Candlestick Questions 3

87k+ Posts
348 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?