This indicator recognize about 13 candlestick patterns and draw their names with green and red arrows on chart:
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
You must be logged in to post a comment.
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")
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
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
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.
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!
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
hello excuse my english, but i didn't see spinning candle detection ? can you add it please !
Hi Nicolas,
Can this be edited to only show bullish/ bearish engulfing .
Darragh
c fait :-) https://www.prorealcode.com/topic/pro-screeners-trend-reversal-continuation-patterns/