I'm using ta-lib for pattern recognition of candlesticks, however, I'm getting different numbers based on the pattern function I've used. Is there any reference what these numbers represent?
4 Answers
-200 / -100 / 0 / +100 / +200
+200 bullish pattern with confirmation
+100 bullish pattern (most cases)
0 none
-100 bearish pattern
-200 bearish pattern with confirmation
for example
in case of CDLHIKKAKE pattern detection function:
as you can see in the source:
https://sourceforge.net/p/ta-lib/code/HEAD/tree/trunk/ta-lib/c/src/ta_func/ta_CDLHIKKAKE.c#l240
you can get one more -100 or +100 (that makes it -200/+200):
if your pattern have confirmation.
so the calculation will be (pattern+confirmation)
in that way,
you can potentially detect bearish pattern on some days, and one more day that confirm the pattern. and for the end get -200

- 3,017
- 1
- 37
- 43
It's TA-Lib's library who returns -100..+100 values. Wrapper changes nothing.
The interpretation may vary in different functions but in general: value == 0 is false and value != 0 is true. Sign might represent direction.
As for CDLHANGINGMAN, its C code is here.
According to description:
/* Proceed with the calculation for the requested range.
* Must have:
* - small real body
* - long lower shadow
* - no, or very short, upper shadow
* - body above or near the highs of the previous candle
* The meaning of "short", "long" and "near the highs" is specified with TA_SetCandleSettings;
* outInteger is negative (-1 to -100): hanging man is always bearish;
* the user should consider that a hanging man must appear in an uptrend, while this function does not consider it
*/
Although I think it's quite incorrect because CDLHANGINGMAN returns only -100 or 0.
if( TA_REALBODY(i) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal, i ) && // small rb
TA_LOWERSHADOW(i) > TA_CANDLEAVERAGE( ShadowLong, ShadowLongPeriodTotal, i ) && // long lower shadow
TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) && // very short upper shadow
min( inClose[i], inOpen[i] ) >= inHigh[i-1] - TA_CANDLEAVERAGE( Near, NearPeriodTotal, i-1 ) // rb near the prior candle's highs
)
outInteger[outIdx++] = -100;
else
outInteger[outIdx++] = 0;
You can't get +100 from this function at all.
I haven't seen any complete reference. It's better to take a look into TA-func code to be sure. Candle funcs' code is quite simple.

- 2,843
- 26
- 39
-
I did not only try one candle pattern, and when I said other numbers, I meant in other patterns they show up. I only had hanging man as an example. However, reading more into source code, I have a much better feeling how the code works. Thnx – Mostafa Zamani Apr 24 '16 at 19:03
According to this discussion :
The -100 denotes a bearish Tristar pattern where the middle candle body is above the other two. Conversely +100 denotes a bullish Tristar pattern where the middle body is below the adjacent ones.
The page shows a few examples and the relevant source code.
/* Proceed with the calculation for the requested range.
* Must have:
* - 3 consecutive doji days
* - the second doji is a star
* The meaning of "doji" is specified with TA_SetCandleSettings
* outInteger is positive (1 to 100) when bullish or negative (-1 to -100) when bearish
*/
i = startIdx;
outIdx = 0;
do
{
if( TA_REALBODY(i-2) <= TA_CANDLEAVERAGE( BodyDoji, BodyPeriodTotal, i-2 ) && // 1st: doji
TA_REALBODY(i-1) <= TA_CANDLEAVERAGE( BodyDoji, BodyPeriodTotal, i-2 ) && // 2nd: doji
TA_REALBODY(i) <= TA_CANDLEAVERAGE( BodyDoji, BodyPeriodTotal, i-2 ) ) { // 3rd: doji
outInteger[outIdx] = 0;
if ( TA_REALBODYGAPUP(i-1,i-2) // 2nd gaps up
&&
max(inOpen[i],inClose[i]) < max(inOpen[i-1],inClose[i-1]) // 3rd is not higher than 2nd
)
outInteger[outIdx] = -100;
if ( TA_REALBODYGAPDOWN(i-1,i-2) // 2nd gaps down
&&
min(inOpen[i],inClose[i]) > min(inOpen[i-1],inClose[i-1]) // 3rd is not lower than 2nd
)
outInteger[outIdx] = +100;
outIdx++;
}
else
outInteger[outIdx++] = 0;
/* add the current range and subtract the first range: this is done after the pattern recognition
* when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle)
*/
BodyPeriodTotal += TA_CANDLERANGE( BodyDoji, i-2 ) - TA_CANDLERANGE( BodyDoji, BodyTrailingIdx );
i++;
BodyTrailingIdx++;
} while( i <= endIdx );

- 15,779
- 10
- 54
- 75
-
These numbers are found when searching for any pattern and not only Tristar though? also, I'm getting straight -100, or +100 and not ranges. I'm using real `ohlc` data, so I was hoping ta-lib to give me a range between -100 and +100, and not just a +100 , -100. – Mostafa Zamani Apr 24 '16 at 08:48
-
i'm reading the source code from here, http://ta-lib.org/hdr_dev.html, I don't want to be naive, but could this be caused by python wrapper, hmmm? – Mostafa Zamani Apr 24 '16 at 08:58
-
Could you please post some code so that we can better understand which function you are using ? – Jacques Gaudin Apr 24 '16 at 10:55
-
`y = talib.CDLHANGINGMAN(open_np, high_np, low_np, close_np)` and then I `print y` and the output is `[ 0 0 -100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]` – Mostafa Zamani Apr 24 '16 at 14:54
Refering to this video. He explains the -100 and 100. It even references this very page.
https://youtu.be/lrYu9AnPw7Q?t=120
https://github.com/mrjbq7/ta-lib/issues/74
**The -100 denotes a bearish Tristar pattern where the middle candle body is above the other two. Conversely +100 denotes a bullish Tristar pattern where the middle body is below the adjacent ones.
What are the numbers such as -100, +100, -200, +200 and etc, when using ta-lib in Python?**

- 161
- 2
- 14