Pharos
TAKline

吞没形态 (Engulfing Pattern)

函数签名

python
TA.CDLENGULFING(opens, highs, lows, closes) -> array

功能说明

吞没形态是一个双向反转形态,由两根K线组成,第二根K线的实体完全吞没第一根K线的实体。

形态特征

看涨吞没 (Bullish Engulfing)

第一根: 阴线(实体较小)
第二根: 阳线(实体完全吞没第一根)

条件:

  • 第二根开盘价 < 第一根收盘价
  • 第二根收盘价 > 第一根开盘价
  • 出现在下跌趋势中

看跌吞没 (Bearish Engulfing)

第一根: 阳线(实体较小)
第二根: 阴线(实体完全吞没第一根)

条件:

  • 第二根开盘价 > 第一根收盘价
  • 第二根收盘价 < 第一根开盘价
  • 出现在上涨趋势中

参数说明

参数类型说明
opensarray开盘价数组
highsarray最高价数组
lowsarray最低价数组
closesarray收盘价数组

返回值

返回整数数组:

  • 100: 看涨吞没
  • 0: 无形态
  • -100: 看跌吞没

使用示例

基础用法

python
def main():
    while True:
        records = exchange.GetRecords()
        if len(records) < 10:
            Sleep(1000)
            continue
        
        opens = [r['Open'] for r in records]
        highs = [r['High'] for r in records]
        lows = [r['Low'] for r in records]
        closes = [r['Close'] for r in records]
        
        engulfing = TA.CDLENGULFING(opens, highs, lows, closes)
        
        if engulfing[-1] == 100:
            Log("看涨吞没,买入信号")
        elif engulfing[-1] == -100:
            Log("看跌吞没,卖出信号")
        
        Sleep(60000)

结合趋势判断

python
def main():
    while True:
        records = exchange.GetRecords()
        if len(records) < 100:
            Sleep(1000)
            continue
        
        opens = [r['Open'] for r in records]
        highs = [r['High'] for r in records]
        lows = [r['Low'] for r in records]
        closes = [r['Close'] for r in records]
        
        # 检测吞没形态
        engulfing = TA.CDLENGULFING(opens, highs, lows, closes)
        
        # 趋势判断
        sma20 = TA.SMA(closes, 20)
        sma50 = TA.SMA(closes, 50)
        
        # 看涨吞没 + 下跌趋势
        if engulfing[-1] == 100 and closes[-1] < sma20[-1] < sma50[-1]:
            Log("下跌趋势中出现看涨吞没,强烈买入信号")
            Log(f"入场价: {closes[-1]}")
            Log(f"止损: {lows[-1] * 0.98}")
        
        # 看跌吞没 + 上涨趋势
        elif engulfing[-1] == -100 and closes[-1] > sma20[-1] > sma50[-1]:
            Log("上涨趋势中出现看跌吞没,强烈卖出信号")
            Log(f"入场价: {closes[-1]}")
            Log(f"止损: {highs[-1] * 1.02}")
        
        Sleep(60000)

吞没强度分析

python
def analyze_engulfing_strength(opens, highs, lows, closes):
    """分析吞没形态的强度"""
    if len(closes) < 2:
        return None
    
    # 计算实体大小
    body1 = abs(closes[-2] - opens[-2])
    body2 = abs(closes[-1] - opens[-1])
    
    # 吞没比例
    ratio = body2 / body1 if body1 > 0 else 0
    
    # 第二根K线的影线
    upper_shadow = highs[-1] - max(opens[-1], closes[-1])
    lower_shadow = min(opens[-1], closes[-1]) - lows[-1]
    
    strength = {
        'ratio': ratio,
        'upper_shadow': upper_shadow,
        'lower_shadow': lower_shadow,
        'has_gap': opens[-1] > closes[-2] or opens[-1] < closes[-2]  # 是否跳空
    }
    
    # 评分
    score = 0
    if ratio > 2: score += 2  # 大幅吞没
    elif ratio > 1.5: score += 1
    
    if strength['has_gap']: score += 1  # 跳空开盘
    
    if upper_shadow < body2 * 0.2 and lower_shadow < body2 * 0.2:
        score += 1  # 影线短
    
    strength['score'] = score
    return strength

def main():
    while True:
        records = exchange.GetRecords()
        if len(records) < 100:
            Sleep(1000)
            continue
        
        opens = [r['Open'] for r in records]
        highs = [r['High'] for r in records]
        lows = [r['Low'] for r in records]
        closes = [r['Close'] for r in records]
        
        engulfing = TA.CDLENGULFING(opens, highs, lows, closes)
        
        if engulfing[-1] == 100:
            strength = analyze_engulfing_strength(opens, highs, lows, closes)
            Log(f"看涨吞没强度: {strength['score']}/4")
            Log(f"吞没比例: {strength['ratio']:.2f}")
            
            if strength['score'] >= 3:
                Log("⭐ 高质量吞没形态,强烈买入!")
        
        elif engulfing[-1] == -100:
            strength = analyze_engulfing_strength(opens, highs, lows, closes)
            Log(f"看跌吞没强度: {strength['score']}/4")
            
            if strength['score'] >= 3:
                Log("⭐ 高质量吞没形态,强烈卖出!")
        
        Sleep(60000)

双向交易系统

python
def main():
    position = None
    
    while True:
        records = exchange.GetRecords()
        if len(records) < 100:
            Sleep(1000)
            continue
        
        opens = [r['Open'] for r in records]
        highs = [r['High'] for r in records]
        lows = [r['Low'] for r in records]
        closes = [r['Close'] for r in records]
        volumes = [r['Volume'] for r in records]
        
        engulfing = TA.CDLENGULFING(opens, highs, lows, closes)
        atr = TA.ATR(highs, lows, closes, 14)
        
        # 成交量确认
        vol_sma = TA.SMA(volumes, 20)
        vol_confirm = volumes[-1] > vol_sma[-1] * 1.3
        
        # 买入
        if position is None and engulfing[-1] == 100 and vol_confirm:
            price = closes[-1]
            stop_loss = price - atr[-1] * 2
            take_profit = price + atr[-1] * 3
            
            Log(f"看涨吞没买入 @ {price}")
            position = {
                'direction': 'LONG',
                'entry': price,
                'stop': stop_loss,
                'target': take_profit
            }
        
        # 卖出(做空)
        elif position is None and engulfing[-1] == -100 and vol_confirm:
            price = closes[-1]
            stop_loss = price + atr[-1] * 2
            take_profit = price - atr[-1] * 3
            
            Log(f"看跌吞没卖出 @ {price}")
            position = {
                'direction': 'SHORT',
                'entry': price,
                'stop': stop_loss,
                'target': take_profit
            }
        
        # 平仓逻辑
        elif position is not None:
            current = closes[-1]
            
            if position['direction'] == 'LONG':
                if current < position['stop']:
                    Log("多单止损")
                    position = None
                elif current > position['target']:
                    Log("多单止盈")
                    position = None
                elif engulfing[-1] == -100:  # 反向信号
                    Log("反向信号平多")
                    position = None
            
            else:  # SHORT
                if current > position['stop']:
                    Log("空单止损")
                    position = None
                elif current < position['target']:
                    Log("空单止盈")
                    position = None
                elif engulfing[-1] == 100:  # 反向信号
                    Log("反向信号平空")
                    position = None
        
        Sleep(60000)

识别要点

高质量吞没形态

✅ 第二根实体完全吞没第一根
✅ 第二根实体是第一根的1.5倍以上
✅ 第二根影线很短
✅ 开盘跳空
✅ 成交量放大
✅ 出现在明确趋势中

低质量吞没形态

⚠️ 刚好吞没,比例接近1
⚠️ 第二根影线很长
⚠️ 没有跳空
⚠️ 成交量萎缩
⚠️ 出现在震荡中

实战技巧

1. 判断吞没强度

python
# 计算吞没比例
body1 = abs(closes[-2] - opens[-2])
body2 = abs(closes[-1] - opens[-1])
ratio = body2 / body1

if ratio > 2:
    Log("强力吞没 - 信号强")
elif ratio > 1.5:
    Log("中等吞没 - 信号中")
else:
    Log("弱吞没 - 谨慎")

2. 跳空确认

python
# 看涨吞没跳空向下开盘
bullish_gap = (engulfing[-1] == 100 and 
               opens[-1] < closes[-2])

# 看跌吞没跳空向上开盘
bearish_gap = (engulfing[-1] == -100 and 
               opens[-1] > closes[-2])

3. 止损设置

python
# 看涨吞没止损
if engulfing[-1] == 100:
    stop_loss = min(lows[-2], lows[-1]) * 0.98

# 看跌吞没止损
if engulfing[-1] == -100:
    stop_loss = max(highs[-2], highs[-1]) * 1.02

可靠性分析

评估项评分
整体可靠性⭐⭐⭐⭐ (高)
单独使用⭐⭐⭐ (可以)
结合趋势⭐⭐⭐⭐⭐ (强烈推荐)
结合成交量⭐⭐⭐⭐⭐ (强烈推荐)

统计数据

  • 胜率: 约60-65%(单独使用)
  • 胜率: 约75-80%(结合确认)
  • 最佳时间周期: 日线、4小时
  • 适用市场: 所有市场

常见组合

吞没 + RSI

python
engulfing = TA.CDLENGULFING(opens, highs, lows, closes)
rsi = TA.RSI(closes, 14)

# 看涨吞没 + RSI超卖
if engulfing[-1] == 100 and rsi[-1] < 30:
    Log("吞没 + RSI超卖 = 强烈买入")

# 看跌吞没 + RSI超买
if engulfing[-1] == -100 and rsi[-1] > 70:
    Log("吞没 + RSI超买 = 强烈卖出")

吞没 + 布林带

python
engulfing = TA.CDLENGULFING(opens, highs, lows, closes)
upper, middle, lower = TA.BBANDS(closes, 20, 2, 2)

# 下轨 + 看涨吞没
if engulfing[-1] == 100 and closes[-2] < lower[-2]:
    Log("布林下轨 + 看涨吞没 = 买入")

# 上轨 + 看跌吞没
if engulfing[-1] == -100 and closes[-2] > upper[-2]:
    Log("布林上轨 + 看跌吞没 = 卖出")

注意事项

⚠️ 重要提示:

  1. 需要TA-Lib库: 此函数依赖TA-Lib
  2. 趋势重要: 在明确趋势中使用效果最佳
  3. 成交量确认: 第二根K线成交量应放大
  4. 比例很重要: 吞没比例越大,信号越强
  5. 避免震荡市: 震荡市中吞没形态可靠性降低

相关形态

返回

返回K线形态目录