ta-lib兩隻烏鴉形態識別實現分析。
k線形態需要回溯前面走勢,並判斷當前形態是否滿足一定條件,如果我自己寫可能會存在較多if else。因此今天研究下cdl2Crows的實現學習下。
k線默認配置
從默認配置可以查看作者對一些形態的基本判斷。
private CandleSetting TA_CandleDefaultSettings[] = {
/*
* real body is long when it's longer than the average of the 10
* previous candles' real body
*/
new CandleSetting(CandleSettingType.BodyLong,
RangeType.RealBody, 10, 1.0),
/*
* real body is very long when it's longer than 3 times the average
* of the 10 previous candles' real body
*/
new CandleSetting(CandleSettingType.BodyVeryLong,
RangeType.RealBody, 10, 3.0),
/*
* real body is short when it's shorter than the average of the 10
* previous candles' real bodies
*/
new CandleSetting(CandleSettingType.BodyShort,
RangeType.RealBody, 10, 1.0),
/*
* real body is like doji's body when it's shorter than 10% the
* average of the 10 previous candles' high-low range
*/
new CandleSetting(CandleSettingType.BodyDoji,
RangeType.HighLow, 10, 0.1),
/* shadow is long when it's longer than the real body */
new CandleSetting(CandleSettingType.ShadowLong,
RangeType.RealBody, 0, 1.0),
/* shadow is very long when it's longer than 2 times the real body */
new CandleSetting(CandleSettingType.ShadowVeryLong,
RangeType.RealBody, 0, 2.0),
/*
* shadow is short when it's shorter than half the average of the 10
* previous candles' sum of shadows
*/
new CandleSetting(CandleSettingType.ShadowShort,
RangeType.Shadows, 10, 1.0),
/*
* shadow is very short when it's shorter than 10% the average of
* the 10 previous candles' high-low range
*/
new CandleSetting(CandleSettingType.ShadowVeryShort,
RangeType.HighLow, 10, 0.1),
/* when measuring distance between parts of candles or width of gaps */
/*
* "near" means "<= 20% of the average of the 5 previous candles'
* high-low range"
*/
new CandleSetting(CandleSettingType.Near,
RangeType.HighLow, 5, 0.2),
/* when measuring distance between parts of candles or width of gaps */
/*
* "far" means ">= 60% of the average of the 5 previous candles'
* high-low range"
*/
new CandleSetting(CandleSettingType.Far,
RangeType.HighLow, 5, 0.6),
/* when measuring distance between parts of candles or width of gaps */
/*
* "equal" means "<= 5% of the average of the 5 previous candles'
* high-low range"
*/
new CandleSetting(CandleSettingType.Equal,
RangeType.HighLow, 5, 0.05) };
代碼
三日K線模式,第一天長陽,第二天高開收陰,第三天再次高開繼續收陰,收盤比前一日收盤價低,預示股價下跌。