TAKline
长线 (Long Line)
TA.CDLLONGLINE() - 中性识别形态
语法
python
result = TA.CDLLONGLINE(records)参数
| 参数 | 类型 | 说明 |
|---|---|---|
| records | array | K线数据数组 |
返回值
- 100: 检测到长线K线
- 0: 无长线K线
形态特征
长线是单日中性形态:
- 实体很长
- 影线较短
- 整根K线高度较大
- 显示市场波动大,趋势强劲
信号解读
- 趋势强劲 (100)
- 单边行情
- 波动率增加
- 交易活跃
- 方向取决于K线颜色
应用场景:
- 白色长线:强势上涨
- 黑色长线:强势下跌
- 需要结合趋势判断是延续还是反转
使用示例
python
def onTick():
exchange.SetContractType("swap")
records = exchange.GetRecords()
if len(records) < 100:
return
# 检测长线
longline = TA.CDLLONGLINE(records)
if longline[-1] == 100:
# 判断K线颜色
is_bullish = records[-1].Close > records[-1].Open
# 计算K线实体大小
body_size = abs(records[-1].Close - records[-1].Open)
avg_body = sum([abs(r.Close - r.Open) for r in records[-20:-1]]) / 19
if body_size > avg_body * 2: # 实体超过平均2倍
ma20 = TA.MA(records, 20)
if is_bullish and records[-1].Close > ma20[-1]:
Log("白色长线突破均线,强势上涨")
# 追涨
exchange.SetDirection("buy")
exchange.Buy(-1, 1)
elif not is_bullish and records[-1].Close < ma20[-1]:
Log("黑色长线跌破均线,强势下跌")
# 追跌
exchange.SetDirection("sell")
exchange.Sell(-1, 1)