ta-lib-python
ta-lib-python copied to clipboard
CDLCLOSINGMARUBOZU issue - not working properly
The following code shows that the Closing MARUBOZU does not work properly. It suggests that there is a closing MARUBOZU on the last candle, which does not conform to the specification, since high is not equal to close. It works if only the last four values are present.
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
#import locale #from locale import atof, setlocale #locale.setlocale(locale.LC_NUMERIC, "nb_NO.UTF-8")
o = np.array([49.09,53.0,49.54,48.84,51.79,49.95,49.59,51.4, 49.0,49.0,47.84]) h = np.array([52.09,55.2,51.2,51.79,52.59,50.5,52.0,51.7,50.59,49.95,52.09]) l = np.array([47.4,52.09,48.2,48.84,49.9,48.65,49.04,48.04,48.29,47.09,47.59]) c = np.array([52.0,52.7,48.65,51.7,49.95,49.04,51.5, 49.2,48.9,47.9,51.9])
print('CDLCLOSINGMARUBOZU ', ta.CDLCLOSINGMARUBOZU(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')
I have tested the .Net version, and it does not give a Closing MARUBOZU on the last sample. It does give a Closing MARUBOZU on the first sample though. I don't like it, but HIGH 52.09 and CLOSE 52.0 is probably better than giving a Closing MARUBOZU with HIGH 52.09 and CLOSE on 51.9.
If you look at the comments in ta_CDLCLOSINGMARUBOZU.c you see:
/* Proceed with the calculation for the requested range.
* Must have:
* - long white (black) real body
* - no or very short upper (lower) shadow
* The meaning of "long" and "very short" is specified with TA_SetCandleSettings
* outInteger is positive (1 to 100) when white (bullish), negative (-1 to -100) when black (bearish)
*/
with the corresponding specifications from ta_global.c being
/* real body is long when it's longer than the average of the 10 previous candles' real body */
{ TA_BodyLong, TA_RangeType_RealBody, 10, 1.0 }
and
/* 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 }
The Closing Marubozu function is working correctly against its own definitions. This is a different definition to many where a white Closing Marubozo has no upper shadow and a black Closing Marubozu has no lower shadow.
(With regards to your .Net tests, it's not possible in Ta_Lib for a candle pattern to be identified on the first bar as there are no averages for length of real body or for the high-low range. Was your data somehow reversed?)
I second this @arnwik.
The way Closing Marubozu is calculated and represented, as @pcawthron mentioned, is not in line with how the majority of traders view a closing marubozu. The common view for marubozu is that it the close shouldn't have a shadow/tail depending if its bull/bearish.
I'm quite new with TA-Lib (has just started looking at the candlestick pattern recognition) but some tests from yesterday recognized this pattern where I (and probably the majority) normally wouldn't call it a marubozu.
OHLC Bull [231.8, 233.9, 231, 233.6] Bear [435.2, 437,6, 419,8, 421,1]
Even though it is close to being correct, in this case I rather not have it recognize the pattern at all if it can't find a proper fit. It would be way more suitable for me rather than having it recognizing a "false" one.
References: http://thepatternsite.com/CloseBlkMarubozu.html http://thepatternsite.com/ClosingWhiteMarubozu.html
Other than that, looking forward dwelling deeper in TA-Lib :).
---edit---- Oh, I noticed now that the TA Lib source code hasn't been updated in years (latest upload to sourceforge was 2007?)... I guess I'll have to do some workarounds to make Marubozu, and potentially other patterns, fit my needs then?
Or do you have any input on this @mrjbq7 ?