Nicolas

Candlestick patterns recognition

Category: Indicators By: Nicolas Created: July 17, 2016, 6:57 PM
July 17, 2016, 6:57 PM
Indicators
42 Comments
Candlestick patterns recognition

This indicator recognize about 13 candlestick patterns and draw their names with green and red arrows on chart:

  • Doji
  • Evening star
  • Morning star
  • Shooting star
  • Hammer
  • Inverted hammer
  • Bearish harami
  • Bullish harami
  • Bearish engulfing
  • Bullish engulfing
  • Piercing line
  • Hanging man
  • Dark cloud cover

I know a lot of people are looking for codes for candlestick pattern recognition, I stumble upon this pinescript code at TV so I decided to convert it to prorealtime.

The patterns tests are stored into “data” variables, so these codes snippets can be taken to make other indicators, trading strategies or screeners with ease.

Text colour can be changed with the R.G.B. values at the beginning of the code.

//text color
// white = 255,255,255 ; black = 0,0,0
r = 255
g = 255
b = 255

atr = averagetruerange[10](close)*0.5

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

data2=(close[2] > open[2] and min(open[1], close[1]) > close[2] and open < min(open[1], close[1]) and close < open )
if data2 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

data3=(close[2] < open[2] and max(open[1], close[1]) < close[2] and open > max(open[1], close[1]) and close > open )
if data3 then
 DRAWTEXT("Morning Star", barindex, low[1]-atr*1.5, Dialog, Standard, 12) COLOURED(0,255,10)
 DRAWARROWUP(barindex-1,low[1]) COLOURED(0,255,10)
endif

data4=(open[1] < close[1] and open > close[1] and high - max(open, close) >= abs(open - close) * 3 and min(close, open) - low <= abs(open - close))
if data4 then
 DRAWTEXT("Shooting Star", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
 DRAWARROWDOWN(barindex,high) COLOURED(255,0,10)
endif

data5=(((high - low)>3*(open -close)) and  ((close - low)/(.001 + high - low) > 0.6) and ((open - low)/(.001 + high - low) > 0.6))
if data5 then
 DRAWTEXT("Hammer", barindex, high+atr, Dialog, Standard, 12) COLOURED(R,G,B)
endif

data5b=(((high - low)>3*(open -close)) and  ((high - close)/(.001 + high - low) > 0.6) and ((high - open)/(.001 + high - low) > 0.6))
if data5b then
 DRAWTEXT("Inverted Hammer", barindex, high+atr, Dialog, Standard, 12) COLOURED(R,G,B)
endif

data6=(close[1] > open[1] and open > close and open <= close[1] and open[1] <= close and open - close < close[1] - open[1] )
if data6 then
 DRAWTEXT("Bearish Harami", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
 DRAWARROWDOWN(barindex,high) COLOURED(255,0,10)
endif

data7=(open[1] > close[1] and close > open and close <= open[1] and close[1] <= open and close - open < open[1] - close[1] )
if data7 then
 DRAWTEXT("Bullish Harami", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,255,10)
 DRAWARROWUP(barindex,low) COLOURED(0,255,10)
endif

data8=(close[1] > open[1] and open > close and open >= close[1] and open[1] >= close and open - close > close[1] - open[1] )
if data8 then
 DRAWTEXT("Bearish Engulfing", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
 DRAWARROWDOWN(barindex,high) COLOURED(255,0,10)
endif

data9=(open[1] > close[1] and close > open and close >= open[1] and close[1] >= open and close - open > open[1] - close[1] )
if data9 then
 DRAWTEXT("Bullish Engulfing", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,255,10)
 DRAWARROWUP(barindex,low) COLOURED(0,255,10)
endif

data10=(close[1] < open[1] and  open < low[1] and close > close[1] + ((open[1] - close[1])/2) and close < open[1])
if data10 then
 DRAWTEXT("Piercing Line", barindex, low-atr*1.5, Dialog, Standard, 12) COLOURED(0,255,10)
 DRAWARROWUP(barindex,low) COLOURED(0,255,10)
endif

data14=(((high-low>4*(open-close))and((close-low)/(.001+high-low)>=0.75)and((open-low)/(.001+high-low)>=0.75)) and high[1] < open and high[2] < open)
if data14 then
 DRAWTEXT("Hanging Man", barindex, high+atr*1.5, Dialog, Standard, 12) COLOURED(255,0,10)
 DRAWARROWDOWN(barindex,high) COLOURED(255,0,10)
endif

data15=((close[1]>open[1])and(((close[1]+open[1])/2)>close)and(open>close)and(open>close[1])and(close>open[1])and((open-close)/(.001+(high-low))>0.6))
if data15 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

RETURN

 

Download
Filename: PRC_CandlesticksPatterns.itf
Downloads: 1979
Nicolas
Nicolas Legend
I created ProRealCode because I believe in the power of shared knowledge. I spend my time coding new tools and helping members solve complex problems. If you are stuck on a code or need a fresh perspective on a strategy, I am always willing to help. Welcome to the community!
Author’s Profile

Comments

Manu L.
6 years ago
#

c fait :-) https://www.prorealcode.com/topic/pro-screeners-trend-reversal-continuation-patterns/

Manu L.
6 years ago
#

Et si je prends éventuellement celui-ci, comment puis je programmer le screener pour qu'il me sorte uniquement la figure qui m'intéresse ? https://www.prorealcode.com/prorealtime-market-screeners/trend-reversal-continuation-patterns/

Nicolas
6 years ago
#

Pour des demandes personnalisées, merci d'utiliser le forum, en ouvrant un nouveau sujet tout en respectant les règles de publication.

Manu L.
6 years ago
#

j'ai pris celui-ci https://www.prorealcode.com/prorealtime-market-screeners/simple-evening-star-morning-star-candlestick-patterns-screener/ mais quand je le lance, j'ai un décalage d'une journée avec ton indicateur //Author: Francesco //Date: 20-01-2017 //BaseCandle parameter = first candle of the pattern, starting from right (it is possible to run screener staring from any past candle) BaseCandle = 0 Open0 = Open[BaseCandle] Close0 = Close[BaseCandle] Open1 = Open[BaseCandle + 1] Close1 = Close[BaseCandle + 1] Open2 = Open[BaseCandle + 2] Close2 = Close[BaseCandle + 2] Open3 = Open[BaseCandle + 3] Close3 = Close[BaseCandle + 3] //Evening Star EvStar = Open0 > Close0 And Open0 Close1 And Close1 > Close2 And Open2 Close3 And Open3 < Close3 //Morning Star MornStar = Open0 Close1 And Open1 < Close1 And Close1 Close2 And Close2 Close3 //Go Short Signal = -1 If EvStar then Go = -1 endif //Go Long Signal = 1 If MornStar then Go = 1 endif Condition = (EvStar Or MornStar) SCREENER[Condition] (Go AS "Go")

Nicolas
6 years ago
#

Si tu utilises un compte gratuit "fin de journée", alors les résultats sont décalés d'1 chandelier, c'est normal.

Manu L.
6 years ago
#

merci mais je voulais utiliser ton indicateur en mode screener et sélectionner uniquement les figures qui m’intéressent

Manu L.
6 years ago
#

Bonjour Nicoles, je continue à bosser tes indicateurs qui sont très pertinent et je m’intéresse à celui-ci. Existe-t-il un screener pour détecter une unique figure : ex. Morning star Merci pour ton aide

Nicolas
6 years ago
#

https://www.prorealcode.com/prorealtime-market-screeners/simple-evening-star-morning-star-candlestick-patterns-screener/ https://www.prorealcode.com/prorealtime-market-screeners/trend-reversal-continuation-patterns/ https://www.prorealcode.com/tag/candlesticks/

Matt B
8 years ago
#

Cypressat, tu as essayé l'autre indicateur que mentionne Nicolas ? https://www.prorealcode.com/prorealtime-indicators/candlesticks-patterns-indicator/

cypressat
8 years ago
#

Merci beaucoup pour cette réponse Nicolas. Je ne peux rien dire parce que je suis totalement ignorant en programmation. Je sais que le logiciel (cher sans doute pas pour rien) de Streve Nison le fait. A la limite, il me semblerait donc polus judicieux de detecter les structures mais sans y adosser le nom. Sinon c'est un peu dangereux pour le débutant. Un débutant qui a appris qu'un marteau est une structure haussière qui en haut de tendance ou somment voit "marteau" pourrait acheter alors qu'il s'agit d'un pendu baissier. Tout est un peu comme ça, des étoiles filantes sont nommées marteau inversé, on trouve des couvertures en nuages noir sur creux (figure de retournement baissière sur sommet), etc ..... Donc sans le nom, le trader voit les figures et à lui de savoir les interpréter en fonction de s'ils les trouvent sur creux, sommet, résistance, support, etc ..... S'il suffisait de juste reconnaître la morphologie... Mais ce n'est pas le cas

Marius
7 years ago
#

Hi, great indicator. I shortened the text for better visuality but there ist a problem. Everything works fine in all timeframes until I switch to the daily chart an higher. Arrows and text appear one candle to the left. How can i fix that? TIA

Nicolas
7 years ago
#

It can happens in weekly chart, there is nothing to do about that.

cypressat
8 years ago
#

Bonjour merci pour ce code. Mais ca ne va pas il ne détecte les structures qu'en fonction de la couleur des chandeliers et non pas en fonction de leur emplacement sur le graphique. Sous résistance si le code détecte une étoile filante il l'appellera marteau inversé au lieu d'étoile filante, comme il apelera un pendu marteau etc .... Ca fausse tout et c'est donc erroné. Je rêve d'un code sachant reconnaître les structure en fonction de l'emplacement (creux, sommet, ligne de tendance, support résistance, niveau de fibonacci, etc ....Et sachant s'adapter en fonction du marché (action, forex) car les structures ne sont pas les m^mes pour cause d'absence de gaps sur le forex

Nicolas
8 years ago
#

Pour cela il faudrait définir comment détecter les supports et résistances, comment et où calculer les niveaux de Fibonacci. Ces niveaux étant très visuels, et le code étant strict, il faut d'abord mettre en corrélation l'homme et la machine :) Ensuite, il est fort probable que nous soyons bloqués par le manque de possibilités du langage de programmation quant aux stockages des données de façon dynamique (pas de tableau de données). Ce code est une conversion fidèle d'un indicateur d'une autre plateforme.

kem2709
9 years ago
#

Wow, I'm speechless, so complete... Thank you!

kem2709
9 years ago
#

Dear Nicolas, Thank you very much for your work. As a beginner, I'm not yet a pro of coding as you are so may I kindly ask for your help? Would it be possible to add the following patterns, too? As per this source (http://thepatternsite.com/CandlePerformers.html), some patterns are more efficient than others. The following 6 ones aren't included in your code and are claimed to be good: 1/ 3 line strike bearish, 2/ 3 line strike bullish, 3/ 3 black crows, 4/ matching low, 5/ abandoned baby bullish, 6/ breakaway bearish. Thank you sooo much in advance, you are the best!

Nicolas
9 years ago
#

Did you try this one? https://www.prorealcode.com/prorealtime-indicators/candlesticks-patterns-indicator/

Gregorinho
9 years ago
#

Hi Nicolas, Thanks for the wonderful work? Do you know if there's a way to say if the candlestick is a hammer and a doji, only write Doji? Because it's often the same ... Thanks. Greg

guinsu2000
9 years ago
#

hello excuse my english, but i didn't see spinning candle detection ?  can you add it please !

Nicolas
9 years ago
#

You should have a look at this other candlesticks patterns indicator: https://www.prorealcode.com/prorealtime-indicators/candlesticks-patterns-indicator/

darraghcoyle77@
9 years ago
#

Hi Nicolas,

Can this be edited to only show bullish/ bearish engulfing .

 

Darragh

Nicolas
10 years ago
#

Another indicator for almost 40 candlesticks patterns identification has been released by Ciccio and it is available here: https://www.prorealcode.com/prorealtime-indicators/candlesticks-patterns-indicator/

Reddi
10 years ago
#

Great Nicolas and Thx,

Nice work. IG has released today PRT 10,3 in Germany and I added the function immediately.

Ciccio
10 years ago
#

There is this Metatrade 4 code that I found around, and it seems more complete than the one posted here

Could someone kindly convert it to Prorealtime code?

Thanks in advance

Nicolas
10 years ago
#

Please use the forums instead! Don't copy/paste codes of entire indicator in comments :) You can upload file in a new forum post query for indicator translation.

Cavok
10 years ago
#

Bonsoir, comment modifier le texte blanc en une autre couleur, le blanc étant extrèmement difficile à lire?

Un grand bravo pour votre travail.

 

Nicolas
10 years ago
#

La définition de la couleur blanche a été volontairement laissé accessible pour modification aux lignes 3,4,5 pour les utilisateurs n'utilisant pas un fond noir pour leurs graphiques (valeurs Rouge, Vert et Bleu à modifier à votre convenance).

GraHal
10 years ago
#

This is soooo good! I'd seen it when I had 10.2 , but forgot until now with 10.3!

Very Big Thanks Nicolas
GraHal

ProRealCode ProRealCode
Loading...