This indicator is a complete candlesticks patterns recognizer indicator. It is a different one and more complete than the other you can find already in the library here.
This indicator recognizes about 40 candlestick patterns and draw their names with green and red arrows on chart (Windows, i.e. gaps, are drawn as “W”):
Since Candlesticks have a meaning only if related to the underlying trend, at the beginning of the code there is also the possibility to change the method used to identify the “trend direction” (1=MACD, 2=SAR [default], 3=Directional Movement)
Original idea and discussions from this topic on forum:
https://www.prorealcode.com/topic/mt4-candlesticks-recognizer-to-be-converted-to-prt-code/
// Trend direction identification
//TDS=2 //(choose 1=MACD, 2=SAR, 3=Directional Movement)
//text color
// white = 255,255,255 ; black = 0,0,0
r = 0
g = 0
b = 0
atr = averagetruerange[10](close)*0.5
body=close-open
abody=abs(body)
if range>0 then
ratio=abody/range
else
ratio=0
endif
middle=(open+close)/2
bodytop=max(open, close)
bodybottom=min(open, close)
shadowtop=high-bodytop
shadowbottom=bodybottom-low
longcandle= (ratio>0.6)
DojiSize = 0.05
data=(abs(open - close) <= (high - low) * DojiSize)
if data then
DRAWTEXT("Doji", barindex, high+atr, Dialog, Standard, 12) COLOURED(R,G,B)
endif
if TDS=1 then
TrendUp=(MACDline[12,26,9](close)>0 AND MACD[12,26,9](close)>0)
TrendDown=(MACDline[12,26,9](close)<0 AND MACD[12,26,9](close)<0)
else
if TDS=2 then
TrendUp=(SAR[0.02,0.02,0.2]<low)
TrendDown=(SAR[0.02,0.02,0.2]>high)
else
if TDS=3 then
TrendUp=(ADX[14]>23 AND DI[14](close)>0)
TrendDown=(ADX[14]>23 AND DI[14](close)<0)
endif
endif
endif
//Bullish Signal
MorningStar=(body[2]<0 and body>0 and longcandle[2] and open[1]<close[2] and open>close[1] and ratio[1]<0.3 and abody[1]<abody[2] and abody[1]<abody and low[1]<low and low[1]<low[2] and high[1]<open[2] and high[1]<close)
if TrendDown[3] AND MorningStar then
DRAWTEXT("Morning Star", barindex, low[1]-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
DRAWARROWUP(barindex-1,low[1]) COLOURED(0,155,10)
endif
PiercingLine=(body[1]<0 and body>0 and longcandle[1] and longcandle and open<low[1] and close>middle[1] and close<open[1])
if TrendDown[2] AND PiercingLine then
DRAWTEXT("Piercing Line", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
DRAWARROWUP(barindex,low) COLOURED(0,155,10)
endif
AbandonedBabyBottom=(body[2]<0 and body>0 and longcandle[2] and ratio[1]<0.3 and high[1]<low[2] and high[1]<low)
if TrendDown[3] AND AbandonedBabyBottom then
DRAWTEXT("Abandoned Baby Bottom", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
DRAWARROWUP(barindex,low) COLOURED(0,155,10)
endif
ThreeInsideUp=(body[2]<0 and body[1]>0 and body>0 and BullishHarami[1] and close>close[1])
if TrendDown[3] AND ThreeInsideUp then
DRAWTEXT("Three Inside Up", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
DRAWARROWUP(barindex,low) COLOURED(0,155,10)
endif
ThreeOutsideUp=(body[2]<0 and body[1]>0 and body>0 and BullishEngulfing[1] and close>close[1])
if TrendDown[3] AND ThreeOutsideUp then
DRAWTEXT("Three Outside Up", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
DRAWARROWUP(barindex,low) COLOURED(0,155,10)
endif
ThreeWhiteSoldiers=(body[2]>0 and body[1]>0 and body>0 and high[1]>high[2] and high>high[1] and close[1]>close[2] and close>close[1] and open[1]>open[2] and open[1]<close[2] and open>open[1] and open<close[1])
if TrendDown[3] AND ThreeWhiteSoldiers then
DRAWTEXT("Three White Soldiers", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
DRAWARROWUP(barindex,low) COLOURED(0,155,10)
endif
ConcealingBabySwallow=(body[3]<0 and body[2]<0 and body[1]<0 and body<0 and ratio[3]>0.8 and ratio[2]>0.8 and ratio>0.8 and open[1]<close[2] and high[1]>close[2] and shadowtop[1]>0.6*(abody[1]+shadowbottom[1]) and bodybottom<bodybottom[1] and bodytop>high[1])
if TrendDown[4] AND ConcealingBabySwallow then
DRAWTEXT("Concealing Baby Swallow", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
DRAWARROWUP(barindex,low) COLOURED(0,155,10)
endif
BullishHarami=(body[1]<0 and body>0 and longcandle[1] and bodybottom>bodybottom[1] and bodytop<bodytop[1])
if TrendDown[2] AND BullishHarami then
DRAWTEXT("Bullish Harami", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
DRAWARROWUP(barindex,low) COLOURED(0,155,10)
endif
BullishEngulfing=(body[1]<0 and body>0 and bodybottom<bodybottom[1] and bodytop>bodytop[1] and longcandle)
if TrendDown[2] AND BullishEngulfing then
DRAWTEXT("Bullish Engulfing", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
DRAWARROWUP(barindex,low) COLOURED(0,155,10)
endif
DragonflyDojiBottom=(body[1]<0 and longcandle[1] and low<low[1] and shadowbottom>3*abody and shadowtop<shadowbottom/3)
if TrendDown[2] AND DragonflyDojiBottom then
DRAWTEXT("Dragonfly Doji", barindex, low-atr, Dialog, Standard, 12) COLOURED(0,155,10)
DRAWARROWUP(barindex,low) COLOURED(0,155,10)
endif
GravestoneDojiBottom=(body[1]<0 and longcandle[1] and low<low[1] and shadowtop>3*abody and shadowbottom<shadowtop/3)
if TrendDown[2] AND GravestoneDojiBottom then
DRAWTEXT("Gravestone Doji", barindex, low-atr, Dialog, Standard, 12) COLOURED(0,155,10)
DRAWARROWUP(barindex,low) COLOURED(0,155,10)
endif
DojiStarBottom=(body[1]<0 AND longcandle[1] AND low<low[1] AND open<close[1] AND ratio<0.3 AND range<0.3*range[1])
if TrendDown[2] AND DojiStarBottom then
DRAWTEXT("Doji", barindex, low-atr, Dialog, Standard, 12) COLOURED(R,G,B)
endif
BullishHaramiCross=(body[1]<0 and longcandle[1] and bodybottom>bodybottom[1] and bodytop<bodytop[1] and ratio<0.3 and range<0.3*range[1])
if TrendDown[2] AND BullishHaramiCross then
DRAWTEXT("Bullish Harami Cross", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
DRAWARROWUP(barindex,low) COLOURED(0,155,10)
endif
ThreeStarsInTheSouth=(body[2]<0 and body[1]<0 and body<0 and shadowtop[2]<range[2]/4 and shadowbottom[2]>abody[2]/2 and low[1]>low[2] and high[1]<high[2] and abody[1]<abody[2] and shadowtop[1]<range[1]/4 and shadowbottom[1]>abody[1]/2 and low>low[1] and high<high[1] and abody<abody[1] and shadowtop<range/4 and shadowbottom<range/4)
if TrendDown[3] AND ThreeStarsInTheSouth then
DRAWTEXT("Three Stars In The South", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
DRAWARROWUP(barindex,low) COLOURED(0,155,10)
endif
BullishBreakaway=(body[4]<0 and body[3]<0 and body>0 and open[3]<close[4] and close[2]<close[3] and close[1]<close[2] and longcandle and close<close[4] and close>open[3])
if TrendDown[5] AND BullishBreakaway then
DRAWTEXT("Bullish Breakaway", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
DRAWARROWUP(barindex,low) COLOURED(0,155,10)
endif
Hammer=(body[1]<0 and longcandle[1] and low<low[1] and shadowbottom>2*abody and shadowtop<0.3*abody)
if TrendDown[2] AND Hammer then
DRAWTEXT("Hammer", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
DRAWARROWUP(barindex,low) COLOURED(0,155,10)
endif
InvertedHammer=(body[1]<0 and longcandle[1] and low<low[1] and shadowtop>2*abody and shadowbottom<0.3*abody)
if TrendDown[2] AND InvertedHammer then
DRAWTEXT("Inverted Hammer", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
DRAWARROWUP(barindex,low) COLOURED(0,155,10)
endif
RisingThreeMethods=(body[4]>0 and body[3]<0 and body[1]<0 and body>0 and longcandle[4] and longcandle and close[2]<close[3] and close[1]<close[2] and high[2]<high[3] and high[1]<high[2] and low[1]>low[4] and open>close[1] and close>high[4] and close>high[3] and close>high[2] and close>high[1])
if TrendUp[5] AND RisingThreeMethods then
DRAWTEXT("Rising Three Methods", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
DRAWARROWUP(barindex,low) COLOURED(0,155,10)
endif
BullishThreeLineStrike=(body[3]>0 and body[2]>0 and body[1]>0 and body<0 and longcandle[3] and longcandle[2] and longcandle[1] and close[2]>close[3] and close[1]>close[2] and open>close[1] and close<open[3])
if TrendUp[4] AND BullishThreeLineStrike then
DRAWTEXT("Bullish Three Line Strike", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
DRAWARROWUP(barindex,low) COLOURED(0,155,10)
endif
BullishMatHold=(body[4]>0 and body[3]<0 and body[1]<0 and body>0 and longcandle[4] and close[3]>close[4] and close[2]<close[3] and close[1]<close[2] and high[2]<high[3] and high[1]<high[2] and low[1]>low[4] and open>close[1] and close>high[4] and close>high[3] and close>high[2] and close>high[1])
if TrendUp[5] AND BullishMatHold then
DRAWTEXT("Bullish Mat Hold", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,155,10)
DRAWARROWUP(barindex,low) COLOURED(0,155,10)
endif
//Bearish Signal
EveningStar=(body[2]>0 AND body<0 and longcandle[2] and open[1]>close[2] and open<close[1] and ratio[1]<0.3 and abody[1]<abody[2] and abody[1]<abody and high[1]>high and high[1]>high[2] and low[1]>open[2] and low[1]>close)
if TrendUp[3] AND EveningStar then
DRAWTEXT("Evening Star", barindex, high[1]+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
DRAWARROWDOWN(barindex-1,high[1]) COLOURED(255,0,10)
endif
DarkCloudCover=(body[1]>0 and body<0 and longcandle[1] and longcandle and open>high[1] and close<middle[1] and close>open[1])
if TrendUp[2] AND DarkCloudCover then
DRAWTEXT("Dark Cloud Cover", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
DRAWARROWDOWN(barindex,high) COLOURED(255,0,10)
endif
AbandonedBabyTop=(body[2]>0 and body<0 and longcandle[2] and ratio[1]<0.3 and low[1]>high[2] and low[1]>high)
if TrendUp[3] AND AbandonedBabyTop then
DRAWTEXT("Abandoned Baby Top", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
DRAWARROWDOWN(barindex,high) COLOURED(255,0,10)
endif
ThreeInsideDown=(body[2]>0 and body[1]<0 and body<0 and bearishharami[1] and close<close[1])
if TrendUp[3] AND ThreeInsideDown then
DRAWTEXT("Three Inside Down", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
DRAWARROWDOWN(barindex,high) COLOURED(255,0,10)
endif
ThreeOutsideDown=(body[2]>0 and body[1]<0 and body<0 and bearishengulfing[1] and close<close[1])
if TrendUp[3] AND ThreeOutsideDown then
DRAWTEXT("Three Outside Down", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
DRAWARROWDOWN(barindex,high) COLOURED(255,0,10)
endif
ThreeBlackCrows=(body[2]<0 and body[1]<0 and body<0 and longcandle[2] and longcandle[1] and longcandle and low[1]<low[2] and low<low[1] and close[1]<close[2] and close<close[1] and open[1]<open[2] and open[1]>close[2] and open<open[1] and open>close[1])
if TrendUp[3] AND ThreeBlackCrows then
DRAWTEXT("Three Black Crows", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
DRAWARROWDOWN(barindex,high) COLOURED(255,0,10)
endif
UpsideGapTwoCrows=(body[2]>0 and body[1]<0 and body<0 and longcandle[2] and open[1]>close[2] and bodytop>bodytop[1] and bodybottom<bodybottom[1] and close>close[2])
if TrendUp[3] AND UpsideGapTwoCrows then
DRAWTEXT("Upside Gap Two Crows", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
DRAWARROWDOWN(barindex,high) COLOURED(255,0,10)
endif
BearishHarami=(body[1]>0 and body<0 and longcandle[1] and bodybottom>bodybottom[1] and bodytop<bodytop[1])
if TrendUp[2] AND BearishHarami then
DRAWTEXT("Bearish Harami", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
DRAWARROWDOWN(barindex,high) COLOURED(255,0,10)
endif
BearishEngulfing=(body[1]>0 and body<0 and bodybottom<bodybottom[1] and bodytop>bodytop[1] and longcandle)
if TrendUp[2] AND BearishEngulfing then
DRAWTEXT("Bearish Engulfing", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
DRAWARROWDOWN(barindex,high) COLOURED(255,0,20)
endif
DragonflyDojiTop=(body[1]>0 and longcandle[1] and high>high[1] and shadowbottom>3*abody and shadowtop<shadowbottom/3)
if TrendUp[2] AND DragonflyDojiTop then
DRAWTEXT("Dragonfly Doji", barindex, high+atr, Dialog, Standard, 12) COLOURED(255,0,10)
DRAWARROWDOWN(barindex,high) COLOURED(255,0,10)
endif
GravestoneDojiTop=(body[1]>0 and longcandle[1] and high>high[1] and shadowtop>3*abody and shadowbottom<shadowtop/3)
if TrendUp[2] AND GravestoneDojiTop then
DRAWTEXT("Gravestone Doji", barindex, high+atr, Dialog, Standard, 12) COLOURED(255,0,10)
DRAWARROWDOWN(barindex,high) COLOURED(255,0,10)
endif
DojiStarTop=(body[1]>0 AND longcandle[1] AND high>high[1] AND open>close[1] AND ratio<0.3 AND range<0.3*range[1])
if TrendUp[2] AND DojiStarTop then
DRAWTEXT("Doji", barindex, high+atr, Dialog, Standard, 12) COLOURED(R,G,B)
endif
BearishHaramiCross=(body[1]>0 and longcandle[1] and bodybottom>bodybottom[1] and bodytop<bodytop[1] and ratio<0.3 and range<0.3*range[1])
if TrendUp[2] AND BearishHaramiCross then
DRAWTEXT("Bearish Harami Cross", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
DRAWARROWDOWN(barindex,high) COLOURED(255,0,10)
endif
AdvanceBlock=(body[2]>0 and body[1]>0 and body>0 and high[2]<high[1] and high[1]<high and open[1]>bodybottom[2] and open[1]<bodytop[2] and open>bodybottom[1] and open<bodytop[1] and abody[1]<abody[2] and abody<abody[1])
if TrendUp[3] AND AdvanceBlock then
DRAWTEXT("Advance Block", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
DRAWARROWDOWN(barindex,high) COLOURED(255,0,10)
endif
TwoCrows=(body[2]>0 and body[1]<0 and body<0 and longcandle[2] and open[1]>close[2] and close[1]>close[2] and open<bodytop[1] and open>bodybottom[1] and close<bodytop[2] and close>bodybottom[2])
if TrendUp[3] AND TwoCrows then
DRAWTEXT("Two Crows", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
DRAWARROWDOWN(barindex,high) COLOURED(255,0,10)
endif
BearishBreakaway=(body[4]>0 and body[3]>0 and body<0 and open[3]>close[4] and close[2]>close[3] and close[1]>close[2] and longcandle and close>close[4] and close<open[3])
if TrendUp[5] AND BearishBreakaway then
DRAWTEXT("Bearish Breakaway", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
DRAWARROWDOWN(barindex,high) COLOURED(255,0,10)
endif
ShootingStar=(body[1]>0 and longcandle[1] and high>high[1] and shadowtop>2*abody and shadowbottom<0.3*abody)
if TrendUp[2] AND ShootingStar then
DRAWTEXT("Shooting Star", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
DRAWARROWDOWN(barindex,high) COLOURED(255,0,10)
endif
HangingMan=(body[1]>0 and longcandle[1] and high>high[1] and shadowbottom>2*abody and shadowtop<0.3*abody)
if TrendUp[2] AND HangingMan then
DRAWTEXT("Hanging Man", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
DRAWARROWDOWN(barindex,high) COLOURED(255,0,10)
endif
FallingThreeMethods=(body[4]<0 and body[3]>0 and body[1]>0 and body<0 and longcandle[4] and longcandle and close[2]>close[3] and close[1]>close[2] and low[2]>low[3] and low[1]>low[2] and high[1]<high[4] and open<close[1] and close<low[4] and close<low[3] and close<low[2] and close<low[1])
if TrendDown[5] AND FallingThreeMethods then
DRAWTEXT("Falling Three Methods", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
DRAWARROWDOWN(barindex,high) COLOURED(255,0,10)
endif
BearishThreeLineStrike=(body[3]<0 and body[2]<0 and body[1]<0 and body>0 and longcandle[3] and longcandle[2] and longcandle[1] and close[2]<close[3] and close[1]<close[2] and open<close[1] and close>open[3])
if TrendDown[4] AND BearishThreeLineStrike then
DRAWTEXT("Bearish Three Line Strike", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
DRAWARROWDOWN(barindex,high) COLOURED(255,0,10)
endif
BearishMatHold=(body[4]<0 and body[3]>0 and body[1]>0 and body<0 and longcandle[4] and close[3]<close[4] and close[2]>close[3] and close[1]>close[2] and low[2]>low[3] and low[1]>low[2] and high[1]<high[4] and open<close[1] and close<low[4] and close<low[3] and close<low[2] and close<low[1])
if TrendDown[5] AND BearishMatHold then
DRAWTEXT("Bearish Mat Hold", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
DRAWARROWDOWN(barindex,high) COLOURED(255,0,10)
endif
//Gaps
GapUp=(low>high[1])
GapDown=(high<low[1])
if GapUp then
DRAWTEXT("W", barindex, (high[1]+low)/2, Dialog, Bold, 12) COLOURED(0,0,255)
else
if GapDown then
DRAWTEXT("W", barindex, (high+low[1])/2, Dialog, Bold, 12) COLOURED(255,0,255)
endif
endif
RETURN