ta-lib-python icon indicating copy to clipboard operation
ta-lib-python copied to clipboard

Candle functions - CDL3BLACKCROWS not working well...

Open Clementstore opened this issue 6 years ago • 4 comments

Dear,

I tried out the CDL3BLACKCROWS function using the following codes. But it doesnt seem to work well..? I am using talib 0.4.17


from plotly.offline import plot
import plotly.graph_objs as go
import pandas as pd
import talib as ta
import re 
import numpy as np

o = np.array([ 39.00, 39.00, 39.00, 39.00, 40.32, 40.51, 38.09, 35.00, 27.66, 30.80, 39.00, 39.00, 39.00, 39.00, 40.51, 38.09, 35.00, 27.66, 30.80])
h = np.array([ 40.84, 39.00, 40.84, 40.84, 41.69, 40.84, 38.12, 35.50, 31.74, 32.51, 40.84, 39.00, 40.84, 40.84, 40.84, 38.12, 35.50, 31.74, 32.51])
l = np.array([ 35.80, 35.80, 35.80, 35.80, 39.26, 36.73, 33.37, 30.03, 27.03, 28.31, 35.80, 35.80, 35.80, 35.80, 36.73, 33.37, 30.03, 27.03, 28.31])
c = np.array([ 40.29, 40.29, 40.29, 40.29, 40.46, 37.08, 33.37, 30.03, 31.46, 28.31, 40.29, 40.29, 40.29, 40.29, 37.08, 33.37, 30.03, 31.46, 28.31])

print('CDL3BLACKCROWS ', ta.CDL3BLACKCROWS(o, h, l, c))

trace = go.Candlestick( #x= pd.to_datetime(dfohlc.index.values),
            open=o,
            high=h,
            low=l,
            close=c)
data = [trace]

plot(data, filename='go_candle1.html')

The run results is: CDL3BLACKCROWS [ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -100 0 0]

And this only shows signal in index 17. Shouldnt it show in index 7 too...? Thanks so much.. I spent days figuring it out but in vain.

image

Clementstore avatar Jan 12 '19 15:01 Clementstore

If you look at the source code for CDL3BLACKCROWS you see its definition:

/* Proceed with the calculation for the requested range.
    * Must have:
    * - three consecutive and declining black candlesticks
    * - each candle must have no or very short lower shadow
    * - each candle after the first must open within the prior candle's real body
    * - the first candle's close should be under the prior white candle's high
    * The meaning of "very short" is specified with TA_SetCandleSettings
    * outInteger is negative (-1 to -100): three black crows is always bearish; 
    * the user should consider that 3 black crows is significant when it appears after a mature advance or at high levels, 
    * while this function does not consider it
    */

And looking at ta_global.c we see how "very short lower shadow" is defined:

 /* shadow is very short when it's shorter than 10% the average of the 10 previous candles' high-low range */
{ TA_ShadowVeryShort, TA_RangeType_HighLow, 10, 0.1 },

Your test data doesn't show the first Three Black Crows pattern as there are insufficient prior candles to calculate an average high-low range. With more data both patterns are identified:

from plotly.offline import plot
import plotly.graph_objs as go
import pandas as pd
import talib as ta
import re 
import numpy as np

o = np.array([ 39.00, 38.00, 39.00, 38.00, 39.00, 38.00, 39.00, 39.00, 39.00, 39.00, 40.32, 40.51, 38.09, 35.00, 27.66, 30.80, 39.00, 39.00, 39.00, 39.00, 40.51, 38.09, 35.00, 27.66, 30.80])
h = np.array([ 41.84, 40.84, 41.84, 40.84, 41.84, 40.84, 40.84, 39.00, 40.84, 40.84, 41.69, 40.84, 38.12, 35.50, 31.74, 32.51, 40.84, 39.00, 40.84, 40.84, 40.84, 38.12, 35.50, 31.74, 32.51])
l = np.array([ 36.80, 35.80, 36.80, 35.80, 36.80, 35.80, 35.80, 35.80, 35.80, 35.80, 39.26, 36.73, 33.37, 30.03, 27.03, 28.31, 35.80, 35.80, 35.80, 35.80, 36.73, 33.37, 30.03, 27.03, 28.31])
c = np.array([ 41.29, 40.29, 41.29, 40.29, 41.29, 40.29, 40.29, 40.29, 40.29, 40.29, 40.46, 37.08, 33.37, 30.03, 31.46, 28.31, 40.29, 40.29, 40.29, 40.29, 37.08, 33.37, 30.03, 31.46, 28.31])

print('CDL3BLACKCROWS ', ta.CDL3BLACKCROWS(o, h, l, c))

trace = go.Candlestick( #x= pd.to_datetime(dfohlc.index.values),
            open=o,
            high=h,
            low=l,
            close=c)
data = [trace]

plot(data, filename='go_candle1.html')
CDL3BLACKCROWS  [   0    0    0    0    0    0    0    0    0    0    0    0    0 -100
    0    0    0    0    0    0    0    0 -100    0    0]

image

pcawthron avatar Dec 02 '19 10:12 pcawthron

I also have strange behaviour with CDLHAMMER

does CDLHAMMER also need more history to work correctly? I thougt it is possible to find out that pattern is matching on a single candle, isn't it?

dsultanr avatar Jan 30 '21 20:01 dsultanr

CDLHAMMER, like all TA-Lib candle functions, needs prior data - usually a default of 10 previous candles - to determine whether a candle's real body and shadows are long, very long, short or very short.

pcawthron avatar Jan 31 '21 16:01 pcawthron