Closed nkta3m closed 2 years ago
Could you please try again with another 10 or more days prior data and report back? TA-Lib needs more prior data than you show here to determine if a candle's real body is (relatively) long or short.
The actual data is from 04/01–21/01, and the screenshot is just for a clearer representation of the real k-line
Thanks for confirming that.
The TA-Lib library has been used for many years so it's almost impossible that CDLEVENINGSTAR would be fundamentally flawed.
The problem you have here is that TA-Lib is using something other than the typical definition of an Evening Star candle. TA-Lib requires: (i) first candle: 'long' white real body (ii) second candle: 'short' body gapping up (iii) third candle: black real body which is longer than 'short' and which closes 'well within' the first candle's real body.
The concepts of 'long', 'short' and 'well within' need to be defined programmatically. TA-Lib has default settings for these which can be changed by editing the source code and rebuilding.
A 'long' real body is defined as longer than 3 times the average of the 10 previous real bodies.
A 'short' real body is defined as shorter that 10% of the average of the 10 previous real bodies.
The values 3, 10 and 10% can be changed in the source file ta_global.c
'Well within' is something I didn't know about until today. It's set by the optInPenetration
setting in the source for each candle pattern that uses it. In the source for CDLEVENINGSTAR it's set at 3.000000e-1 to denote 0.3 or 30%, meaning the close of the third candle must be more than 30% below the close of the first candle. In the code below, the real body of the first candle has a range of 3.20 to 3.60. To get confirmation of an Evening Star candle, I set the close of the third candle to 3.479 as it does not find the candle pattern with a value of 3.48.
I didn't use real data for this, simply data within which TA-Lib can identify the pattern:
Code:
from plotly.offline import plot
import plotly.graph_objs as go
import pandas as pd
import talib as ta
import numpy as np
o = np.array([1.98,1.98,1.98,1.98,2.06,2.04,2.30,2.57,3.01,3.08,3.20,3.82,3.71,3.55,3.08,2.95])
h = np.array([2.07,2.07,2.07,2.07,2.10,2.26,2.49,2.74,3.01,3.31,3.60,4.00,3.92,3.69,3.27,3.29])
l = np.array([1.95,1.95,1.95,1.95,2.03,2.04,2.15,2.57,2.66,2.98,3.14,3.62,3.31,3.23,2.96,2.91])
c = np.array([2.03,2.03,2.03,2.03,2.05,2.26,2.49,2.74,3.01,3.31,3.60,3.78,3.479,3.28,2.99,3.29])
print('CDLEVENINGSTAR ', ta.CDLEVENINGSTAR(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')
Text output:
CDLEVENINGSTAR [ 0 0 0 0 0 0 0 0 0 0 0 0 -100 0
0 0]
Plot:
Thank you very much for the detailed explanation, which I now fully understand.
According to the definition of evening star, the structure of evening star has been formed here, but there is no indication, what is the reason?