4

I'm trying to fiddle with the TA-Lib functions, trying to understand how they identify patterns.

The following code produces strange results

import talib  
import numpy  
sample_data = [  
    ['1/22/14', 10, 18,  5, 20],  
    ['1/23/14', 12, 21,  7, 22],  
    ['1/24/14', 14, 24, 9 , 24],  
    ['1/25/14', 16, 27, 11, 26],  
    ['1/26/14', 18, 30, 13, 28],  
    ['1/27/14', 20, 33, 15, 30],  
    ['1/28/14', 22, 36, 17, 32],  
    ['1/29/14', 24, 39, 19, 34],  
    ['1/30/14', 26, 41, 21, 38],  
    ['1/31/14', 30, 45, 25, 40],  
    ['2/01/14', 43, 44, 42, 43.01],  
    ['2/02/14', 46, 47, 45, 46.01],  
    ['2/03/14', 44, 45, 43, 44.01],  
    ['2/04/14', 40, 55, 35, 50],  
]

# convert data to columns  
sample_data = numpy.column_stack(sample_data)

# extract the columns we need, making sure to make them 64-bit floats  
o = sample_data[1].astype(float)  
h = sample_data[2].astype(float)  
l = sample_data[3].astype(float)  
c = sample_data[4].astype(float)

print(talib.CDLDOJI(o,h,l,c))  

results in :

print(talib.CDLDOJI(o,h,l,c)) [0 0 0 0 0 0 0 0 0 0 0 0 0 0]

If I look at ta_global.c Here

real body is like doji's body when it's shorter than 10% the average of the 10 previous candles' high-low range

{ TA_BodyDoji, TA_RangeType_HighLow, 10, 0.1 },

I figure based on this definition and the definition of ta_CDLDOJI.c here the function should yield three Dojis :

[0 0 0 0 0 0 0 0 0 0 100 100 100 0]

What am I missing here ?

JB Lepetit
  • 211
  • 3
  • 9
  • Rebuilding TA-Lib using the latest source code from the [github master branch](https://github.com/mrjbq7/ta-lib) fixes this issue for me. – cgohlke Aug 16 '16 at 07:18

2 Answers2

2

I've changed the underlying data for it to be even more obivous

sample_data = [ ['1/22/14', 10, 22, 5, 20], ['1/23/14', 12, 23, 7, 22], ['1/24/14', 14, 24, 9 , 24], ['1/25/14', 16, 27, 11, 26], ['1/26/14', 18, 30, 13, 28], ['1/27/14', 20, 33, 15, 30], ['1/28/14', 22, 36, 17, 32], ['1/29/14', 24, 39, 19, 34], ['1/30/14', 26, 41, 21, 38], ['1/31/14', 30, 45, 25, 40], ['2/01/14', 43, 46, 40, 43.001], ['2/02/14', 46, 54, 38, 46.001], ['2/03/14', 39.99, 40.01, 39.99, 40.01], ['2/04/14', 40, 55, 35, 50], ] Where the 12th candle is obviously a doji and where the 13th should also be categorized as such if you were to consider high-low instead of abs(close-open). Both a returned as zero by the CDLDOJI function...

JB Lepetit
  • 211
  • 3
  • 9
  • 1
    Well, first of all I realized that I really misunderstood your point. CDLDOJI really compares `abs(close-open)` to `0.1*avg(high-low)` so you should get [100, 100, 100, 0] as a result. Sorry, for that. Secondly, I've launched the function from my C++ app and got correct result - [100, 100, 100, 0]... – truf Jul 01 '16 at 21:42
  • I managed to setup python environment and launched your code. It provides correct result: `/usr/bin/python2.7 /home/PycharmProjects/untitled/1.py [ 0 0 0 0 0 0 0 0 0 0 100 100 100 0]` – truf Jul 01 '16 at 22:16
1

If you are running python and TA-Lib on Windows, this problem occurs because of issues with the installed TA-Lib binaries.

I checked this on a Linux machine with Python 2.7 after building from source as per https://github.com/mrjbq7/ta-lib. The output is correct as truf has pointed out in his comments.

I observe the problem that you pointed out in my Windows 10 64bit install / Python 2.7 for which i downloaded the whl files for TA-Lib from http://www.lfd.uci.edu/~gohlke/pythonlibs/#ta-lib

Best solution on Windows seems to be build TA-Lib from scratch. But quite a lot of issues on a 64bit box. More info can be found at the issues section of github page for ta-lib by mrjbq7.

trance
  • 128
  • 1
  • 8