基于Steve Nison,《日本蜡烛图技术》(第2版)
Steve Nison是将日本蜡烛图技术引入西方金融世界的个人。在他1991年出版之前,蜡烛图技术在日本以外基本未知。他的贡献不是发明这些方法,而是为西方从业者翻译、系统化和上下文化。
Nison与Morris的区别:
核心原则:"蜡烛图技术不是圣杯。它们是工具——有价值的工具——但必须在其他技术证据的背景下使用。"
日本蜡烛图分析起源于1690年代大阪�的米期货交易所——世界上第一个有组织的期货市场。米不仅是商品,而是日本封建经济的基础;武士俸禄以米支付,米券充当货币形式。
市场产生真正的价格发现:数百名交易商谈判,价格通过屋顶信号网络在大阪和其他城市之间传递。心理动态——恐惧、贪婪、人群行为——与现代金融市场相同,这就是为什么1700年代日本开发的技术今天仍然适用。
Homma(1724-1803)被归功于蜡烛图分析的正式化,尽管历史记录 mixed。清楚的是,一套交易智慧从�的�的�(Homma的出生地)出现,编纂为"坂田方法"(Sakata Senbo)——五种核心形态:
Nison的关键洞察: 这五种方法不仅仅是形态,而是一个完整的市场框架。三山和三川解决主要反转。三空识别耗竭。三兵确认趋势动量。三法识别趋势内的停顿 Together, they cover the full lifecycle of a price move.
Nison翻译了几个编码深层市场智慧的日本交易谚语:
四个数据点——开盘价、最高价、最低价、收盘价——创建蜡烛。Nison的术语偏好:
| Nison的首选术语 | 西方等价物 | 定义 |
|---|---|---|
| 实际体 | 实体 | 开盘和收盘之间的距离 |
| 上影线 | 上影 | 最高价减去实际体顶部 |
| 下影线 | 下影/尾 | 实际体底部减去最低价 |
| 白色蜡烛 | 看涨蜡烛 | 收盘 > 开盘 |
| 黑色蜡烛 | 看跌蜡烛 | 收盘 < 开盘 |
Nison强烈 prefer"实际体"over"body",因为实际体是蜡烛图分析的核心——它代表了开盘和收盘之间价格协议的范围,比阴影捕捉的日内极端更具心理权重。
Nison的重要性层次:
与 rigid 定量定义不同,Nison强调蜡烛图形态 inherent visual and should be interpreted with flexibility:
实施说明: 编码形态检测时,使用 lookback-relative 阈值(例如,body_size > 1.5 * average_body_size_over_N_periods)而非固定百分比。
Nison对反转形态的处理在 emphasis、确认要求,以及他考虑的具体上下文因素方面与Morris不同。本节仅涵盖Nison添加或不同处理的内容。
Nison识别锤子和吊人为相同的物理形状(小实 body 在上端,长下影),但具有根本不同的确认需求:
锤子(看涨,在下降趋势中):
吊人(看跌,在上升趋势中):
Nison的 nuance vs. Morris: Morris在强劲上升趋势中对吊人失败的处理是二元的(无确认则忽略)。Nison补充说,即使"失败的"吊人也揭示了市场日内积极卖出的意愿,这是即时信号失败时的 early warning。
Nison列出了增加吞没形态概率的具体因素:
Nison强调: 成交量是第二根蜡烛的2倍于20日平均的吞没形态与成交量 average 或 below average 的吞没形态是 categorically different。成交量维度不是可选确认——它从根本上改变信号。
Nison对星星形态给予 exceptional attention because they represent the highest probability candlestick reversals。"星星"是一个小的实际体,与前面的大实际体之间存在缺口。
晨星(看涨反转):
Nison对晨星的具体增强:
暮星(看跌反转):
十字星: Nison将十字星视为特殊类别。当十字星在上升趋势中向上缺口于长白蜡烛上方,或在下降趋势中向下缺口于长黑蜡烛下方时,它 immediate significant even without a third candle——十字星本身就是 alarm。第三根蜡烛提供确认。
弃婴: 一种稀有而强大的变体,其中星星(中间蜡烛)是十字星,其阴影不与第一根或第三根蜡烛的阴影重叠。Nison认为这是最可靠的单根蜡烛反转形态,但指出它 extremely rare。
Nison的处理补充:
Nison对渗透要求精确:
Nison对乌云覆盖的附加因素:
Nison提出了Morris不强调的重要观察:刺透线比乌云覆盖有更高的渗透要求,因为日本文献 traditionally treat bottom reversal patterns as needing more proof than top reversals。逻辑:市场可以在自身重量下下跌,但上涨需要买入承诺。
对于刺透线,收盘必须在第一根蜡烛实体的中点上方。Nison指出一些日本分析师要求刺透线穿透先前实体的三分之二才有效。
Nison强调的一个形态,许多西方 treatment跳过:
看涨身怀六甲: 一根长白蜡烛,在会话低点开盘(或非常接近)。没有下影。在下降趋势中出现。在低点开盘表明从开盘时就积极买入。
看跌身怀六甲: 一根长黑蜡烛,在会话高点开盘。没有上影。在上升趋势中出现。
看涨身怀六甲: 看跌身怀六甲:
+---------+ |
| | +---------+
| white | | |
| | | black |
+---------+ | |
| +---------+
识别规则:
两根相反颜色的蜡烛, closing price 相同。Nison将它们视为停顿形态 more than an outright reversal:
看涨反驳: 在下降趋势中,一根长黑蜡烛 followed by a long white candle that opens sharply lower but rallies to close at the same level as the prior close。
看跌反驳: 在上升趋势中,一根长白蜡烛 followed by a long black candle that opens sharply higher but falls to close at the same level as the prior close。
与刺透/乌云的区分: 反驳线有相等的收盘但 NOT penetrate into the prior body。它们标志着僵局,而非控制权转移。
Nison的处理与坂田方法传统一致:
上升三法: 一根长白蜡烛 followed by typically three (but sometimes two or four) small-bodied candles that drift lower within the range of the first candle, concluded by another long white candle that closes above the first candle's close。
Nison的解释说明:
(参见第6节完整窗口处理。)趋势方向的窗口本身就是持续信号——它表明 demand(向上窗口)或 supply(向下窗口)强到足以创造价格真空。
Nison为这些形态提供了原始 Japanese context:
向上跳空并列: 两根白蜡烛之间有一个窗口(缺口), followed by a black candle that opens within the second white body and closes into the gap without filling it。未填补的缺口是关键——这意味着买家尽管回撤仍处于控制之中。
如果缺口被填补: 形态失败,变得看跌。这是Nison强调的一个关键实施细节。
在上升趋势中,一根白蜡烛向上缺口, followed by another white candle of roughly the same size opening at roughly the same level。缺口后的两根并列阳线表明持续买入压力。
看跌版本(向下缺口后在下降趋势中的并列阳线)是 paradoxical——白蜡烛代表未能填补缺口的 short-covering。
Nison坚持使用日本术语 because the Japanese concept is broader and more operationally specific than the Western gap concept:
上升窗口(向上缺口): Functions as support on pullbacks。如果价格回撤至窗口顶部并持稳,它 confirm the bullish trend。如果价格收于窗口底部下方(fully fills it),看涨信号被 negate。
下降窗口(向下缺口): Functions as resistance on rallies。反弹至窗口底部的价格上涨停滞 confirm the bearish trend。
上升窗口: 下降窗口:
+-+ +-+
| | 蜡烛2 | | 蜡烛1
+-+ +-+
... <- 窗口(支撑) ... <- 窗口(阻力)
+-+ +-+
| | 蜡烛1 | | 蜡烛2
+-+ +-+
来自坂田方法:三个连续同向窗口后,move is exhausted and a reversal is likely。这对应于西方的 exhaustion gap 概念 but is stated as a rule rather than a tendency。
实施逻辑:
if count_consecutive_windows_in_direction(candles, direction='up') >= 3:
signal = 'EXHAUSTION_WARNING_BULLISH' # prepare for reversal
# 不要盲目做空——等待看跌反转形态
elif count_consecutive_windows_in_direction(candles, direction='down') >= 3:
signal = 'EXHAUSTION_WARNING_BEARISH'
经测试并保持的窗口(价格进入窗口区域但未收盘超出)是高置信度的持续信号。这是Nison operationally最有用的贡献之一:
交易规则: 上升窗口后,如果价格回撤至窗口区域但下一根收盘回到窗口低点上方,做多(或加仓至已有 long),止损在窗口底部下方。
这是Nison最重要的战略贡献,most clearly distinguishes his work from all other candlestick references。
收敛是多个独立技术方法在同一价格水平或方向结论上达成一致。Nison的论点:蜡烛图信号仅在收敛时才能可操作,at least one (preferably two or more) other technical factors。
蜡烛图 alone 告诉您发生了什么(反转形态已形成)。收敛告诉您它发生在哪里(多个方法确认 significant 的同一水平)。
Nison系统地证明蜡烛图形态在移动平均线水平时获得力量:
具体收敛设置:
在看涨的65日EMA处的看涨形态: Nison偏好65周期EMA(大约一个季度的交易日)。在上升趋势中恰好在65日EMA形成的锤子或晨星是高信念买入信号。
黄金交叉 + 看涨蜡烛: 当较短MA向上穿越较长MA且穿越当日或次日产生看涨蜡烛图形态,收敛非常强劲。
死亡交叉 + 看跌蜡烛: 上方的镜像。
MA作为确认过滤器: 看涨反转形态后,要求价格收于相关MA(例如10周期)上方才能入场。这过滤掉许多假信号。
Nison的具体振荡器收敛规则:
RSI收敛:
随机收敛:
MACD收敛:
趋势线提供 exact price levels;蜡烛图提供 timing signal:
趋势线突破收敛: 向上突破显著趋势线的长白(或黑)蜡烛比小实体蜡烛做同样事情更有意义。突破趋势线的 marubozu 是最强的确认。
这是最常见的收敛应用:
水平S/R + 蜡烛图:
"收敛堆叠": 当三个或更多因素在相同价格水平收敛时,这是Nison的最高置信设置:
最大收敛示例:
- 价格在3个月 pivot 低点的水平支撑 [因素1]
- 200日MA穿过相同价格区域 [因素2]
- RSI在28(超卖) [因素3]
- 晨星在此水平形成 [因素4]
- 晨星第三日成交量 surge [因素5]
信念水平:非常高——部署完整仓位规模
Nison证明在斐波那契回撤水平(38.2%、50%、61.8%)形成的蜡烛图形态具有 elevated reliability:
Nison没有将其 formalize into a scoring system,但他的框架 implied one:
convergence_score = 0
if candlestick_pattern_present: convergence_score += 1
if at_support_or_resistance: convergence_score += 1
if at_moving_average: convergence_score += 1
if oscillator_confirms (oversold/overbought): convergence_score += 1
if volume_confirms: convergence_score += 1
if at_fibonacci_level: convergence_score += 1
if at_trendline: convergence_score += 1
# 决策矩阵
if convergence_score >= 4: action = 'FULL_POSITION'
elif convergence_score == 3: action = 'HALF_POSITION'
elif convergence_score == 2: action = 'SMALL_POSITION_OR_WATCH'
else: action = 'NO_TRADE'
Nison将成交量视为 when candlestick signals are ambiguous 时的决胜局:
volume_ratio = current_volume / SMA(volume, 20)
解释:
> 2.0 = 非常重要——高信念在蜡烛后面
1.5-2.0 = 显著
0.8-1.5 = 正常——形态有效但非 exceptional
< 0.8 = 低信念——将信号降级一个层级
这是Nison引入的三种日本图表类型之一,essentially unknown in Morris's work。三线突破图通过忽略小价格移动 only drawing a new line when price exceeds the extreme of the prior three lines 来过滤噪音。
三根连续白线:
+---------+
| 线 3 | 高 = $52
+---------+
+-------+
| 线 2 | 高 = $50
+-------+
+-----+
|线1| 高 = $48 <- 要变黑,下一收盘必须在$48低点下方
+-----+
Nison的 recommended approach:
砖块图(来自日语"renga",意思是砖)由 uniform-sized bricks 组成。仅当价格移动固定金额("砖块大小")时绘制新砖:
Nison建议:
锚形图使用一系列由短水平线连接的垂直线。线条厚度基于价格是否超过先前的高点或低点:
Nison的实际建议:使用锚形图线厚度作为二元过滤器。当锚形线为粗(阳)时,仅从蜡烛图信号做多。当锚形线为细(阴)时,仅做空或观望。
这 eliminate the most common candlestick error:采取逆趋势信号。
Nison的入场方法建立在收敛概念之上:
1. 使用更高时间框架或替代图表(三线突破、锚形)确定趋势
2. 识别存在收敛的关键价格水平
(S/R + MA + 斐波那契 + 趋势线——2个或更多组合)
3. 等待价格达到收敛区域
4. 在该区域扫描蜡烛图反转形态
5. 验证成交量确认(信号蜡烛成交量比率 > 1.0)
6. 在确认时入场:
保守:下一根收盘确认方向
标准:价格超出形态极端(买入为高点,卖出为低点)
7. 止损在收敛区域下方/上方(而不仅仅是形态极端)
Nison对出场是 pragmatic——他不声称蜡烛图提供精确目标。他的出场框架:
Nison的风险规则很简单:
Nison最强调的警告:"蜡烛图技术不是完整的交易系统。它们是交易系统内的工具。"在没有收敛分析的情况下购买每个锤子和卖出每个流星的交易者将亏损。
关于休息的日本谚语是西方交易者 resist 的实用建议。当市场显示无明确趋势(旋转顶、十字星序列、重叠蜡烛)时,蜡烛图分析说:do nothing。信号 absence IS a signal——它表示市场未准备好 commit,您也不应该。
蜡烛图告诉您何时入场以及哪个方向。它们不告诉您价格将移动多远。在支撑处的晨星告诉您买入,但不预测 rally 是5%还是50%。使用其他工具(斐波那契、measured moves、prior S/R)用于目标。
反转形态需要一些 to reverse。在横向范围内的"看涨吞没"不是看涨吞没——它是 two candles with no directional meaning。始终验证反转形态之前存在 genuine trend。
在周图上形成于 massive bearish engulfing 内的日图看涨锤子不是看涨。Nison建议在 commit to a trade 之前检查至少一个更高时间框架。
Nison在这里比Morris更灵活:如果形态 nearly meets the criteria and occurs at a strong convergence zone,它值得关注。 lower shadow仅为1.8x(不是"要求的"2x)但位于200日MA且RSI为25的锤子仍然是一个 meaningful signal。僵化定量过滤器 reject many valid signals。
设置:
- 股票ABC在6个月内处于上升趋势,从$40上涨到$72。
- 回撤开始:价格在3周内从$72下跌至$58。
- 锚形图仍显示粗(阳)线——长期上升趋势 intact。
- 三线突破图显示两根黑线但尚未产生 turnaround。
收敛区域识别:
- 200日MA在$56.50 [因素1]
- $40-$72涨幅的50%斐波那契回撤 = $56.00 [因素2]
- 3个月前的先前整合支撑在$55-$57 [因素3]
- 来自$40起点的上升趋势线本周触及$56 [因素4]
=> 收敛区域:$55.00-$57.00(四个独立因素 agree)
第1天(周二):
- 开盘$59.20,高$59.50,低$56.80,收盘$57.10
- 长黑蜡烛 plunged into the convergence zone
- 成交量:1.4倍平均(卖出 climax characteristic)
- RSI(14):32,approaching oversold
第2天(周三):
- 开盘$56.50,高$57.00,低$55.60,收盘$56.40
- 小实体(旋转顶/接近十字星),在第1天收盘下方缺口
- 低点$55.60测试趋势线和斐波那契水平
- 成交量:0.7倍平均(犹豫,diminished selling pressure)
- RSI(14):29(超卖)
第3天(周四):
- 开盘$56.80,高$60.20,低$56.60,收盘$59.80
- 长白蜡烛,closes well into 第1天的实体
(第1天实体中点 = ($59.20 + $57.10) / 2 = $58.15;收盘$59.80 > $58.15)
- 成交量:2.3倍平均(买入 surge)
- RSI(14):38(从超卖恢复)
形态:晨星 at convergence zone
收敛检查清单:
[x] 锚形 = 粗线(上升趋势 intact) [过滤器通过]
[x] 晨星在200日MA [因素1]
[x] 晨星在50%斐波那契回撤 [因素2]
[x] 晨星在先前整合支撑 [因素3]
[x] 晨星在上升趋势线 [因素4]
[x] RSI超卖(29) [因素5]
[x] 第3天成交量 surge [因素6]
收敛评分:6 => 完整仓位
入场:$60.30(第3天高点$60.20上方,周五上午触发)
止损:$55.40(第2天低点$55.60下方,趋势线和斐波那契下方)
风险:$60.30 - $55.40 = 每手$4.90
仓位规模:$200,000账户,1.5%风险 = $3,000
股数 = $3,000 / $4.90 = 612股
仓位价值 = 612 * $60.30 = $36,904(账户的18.5%)
目标1:$66.00(先前阻力/127.2%斐波那契扩展) = 1.16:1 R:R
目标2:$72.00(先前高点) = 2.39:1 R:R
目标3:$76.50(161.8%扩展) = 3.31:1 R:R
管理:
- 第5天:价格在$62.50收盘。一根上升窗口(缺口)在第4天高点和第5天低点之间形成。移动止损至$59.80(窗口顶部 = 支撑)。
- 第9天:价格达到$66.00(目标1)。卖出200股。Trailing remaining stop to $63.50(在第7天低点下方)。
- 第12天:价格在$68.50出现看跌孕线。Nison说:tighten stops,不要 outright 退出。移动止损至$66.00。
- 第15天:价格在$68.50上方突破(孕线是停顿,非反转——与锚形仍显示粗线一致)。价格飙升至$71.80。
- 第18天:价格达到$72.00(目标2)。卖出200股。Trailing remaining 212股,止损在$69.50(第16天低点下方)。
- 第22天:暮星在$74.20形成。三线突破图显示序列中最长的白线(potential exhaustion)。在第23天开盘以市场价退出剩余212股$73.50。
结果:
200股 at $66.00:利润 = ($66.00 - $60.30) * 200 = $1,140
200股 at $72.00:利润 = ($72.00 - $60.30) * 200 = $2,340
212股 at $73.50:利润 = ($73.50 - $60.30) * 212 = $2,798
总利润:$6,278(2.09R)
账户回报:3.14%
def detect_rising_window(c1: Candle, c2: Candle) -> bool:
"""当c2的低高于c1的高时,存在上升窗口。"""
return c2.low > c1.high
def detect_falling_window(c1: Candle, c2: Candle) -> bool:
"""当c2的高低于c1的低时,存在下降窗口。"""
return c2.high < c1.low
def count_consecutive_windows(candles: list, direction: str) -> int:
"""计算同向连续窗口数(用于San-ku检测)。"""
count = 0
for i in range(1, len(candles)):
if direction == 'up' and detect_rising_window(candles[i-1], candles[i]):
count += 1
elif direction == 'down' and detect_falling_window(candles[i-1], candles[i]):
count += 1
else:
count = 0 # 序列中断时重置
return count
def window_support_resistance(candles: list) -> list:
"""返回所有未填补窗口作为S/R区域。"""
zones = []
for i in range(1, len(candles)):
if detect_rising_window(candles[i-1], candles[i]):
zone = {'type': 'support', 'top': candles[i].low,
'bottom': candles[i-1].high}
# 检查窗口是否已被填补
filled = any(c.low < zone['bottom'] for c in candles[i+1:])
if not filled:
zones.append(zone)
elif detect_falling_window(candles[i-1], candles[i]):
zone = {'type': 'resistance', 'top': candles[i-1].low,
'bottom': candles[i].high}
filled = any(c.high > zone['top'] for c in candles[i+1:])
if not filled:
zones.append(zone)
return zones
def is_bullish_belt_hold(c: Candle, candles: list, lookback: int = 10) -> bool:
"""看涨身怀六甲:在低点或非常接近低点开盘,长白实体。"""
if not c.is_bullish:
return False
avg_body = sum(abs(x.close - x.open) for x in candles[-lookback:]) / lookback
near_low = c.open - c.low <= c.total_range * 0.02 # 在低点的2%内开盘
long_body = c.body_size > avg_body * 1.5
return near_low and long_body
def is_bearish_belt_hold(c: Candle, candles: list, lookback: int = 10) -> bool:
"""看跌身怀六甲:在高点或非常接近高点开盘,长黑实体。"""
if not c.is_bearish:
return False
avg_body = sum(abs(x.close - x.open) for x in candles[-lookback:]) / lookback
near_high = c.high - c.open <= c.total_range * 0.02
long_body = c.body_size > avg_body * 1.5
return near_high and long_body
def calculate_convergence_score(
candles: list,
current_index: int,
support_levels: list,
resistance_levels: list,
moving_averages: dict, # 例如,{'MA50': 55.0, 'MA200': 56.5}
fibonacci_levels: list, # 例如,[56.0, 53.6, 51.2]
trendlines: list, # (slope, intercept)元组列表
rsi_value: float,
volume_ratio: float,
pattern_type: str # 'bullish_reversal' or 'bearish_reversal'
) -> int:
score = 0
price = candles[current_index].close
tolerance = candles[current_index].total_range * 0.5 # 接近阈值
# 因素1:蜡烛图形态存在(调用者已验证)
score += 1
# 因素2:在支撑(对于看涨)或阻力(对于看跌)
if pattern_type == 'bullish_reversal':
if any(abs(price - level) <= tolerance for level in support_levels):
score += 1
elif pattern_type == 'bearish_reversal':
if any(abs(price - level) <= tolerance for level in resistance_levels):
score += 1
# 因素3:在移动平均线
if any(abs(price - ma_val) <= tolerance for ma_val in moving_averages.values()):
score += 1
# 因素4:在斐波那契水平
if any(abs(price - fib) <= tolerance for fib in fibonacci_levels):
score += 1
# 因素5:在趋势线
for slope, intercept in trendlines:
trendline_price = slope * current_index + intercept
if abs(price - trendline_price) <= tolerance:
score += 1
break
# 因素6:振荡器确认
if pattern_type == 'bullish_reversal' and rsi_value < 30:
score += 1
elif pattern_type == 'bearish_reversal' and rsi_value > 70:
score += 1
# 因素7:成交量确认
if volume_ratio > 1.5:
score += 1
return score
def convergence_decision(score: int) -> str:
if score >= 5:
return 'FULL_POSITION'
elif score == 4:
return 'THREE_QUARTER_POSITION'
elif score == 3:
return 'HALF_POSITION'
elif score == 2:
return 'QUARTER_POSITION_OR_WATCHLIST'
else:
return 'NO_TRADE'
def generate_three_line_break(closes: list) -> list:
"""
从一系列收盘价生成三线突破图数据。
返回每根线的字典列表,包含'高'、'低'、'颜色'。
"""
if len(closes) < 2:
return []
lines = []
# 第一根线
if closes[1] > closes[0]:
lines.append({'high': closes[1], 'low': closes[0], 'color': 'white'})
else:
lines.append({'high': closes[0], 'low': closes[1], 'color': 'black'})
for i in range(2, len(closes)):
last_line = lines[-1]
if last_line['color'] == 'white':
if closes[i] > last_line['high']:
# 继续向上:新白线
lines.append({'high': closes[i], 'low': last_line['high'],
'color': 'white'})
elif len(lines) >= 3:
# 检查反转:必须跌破前三根线的低点
three_line_low = min(l['low'] for l in lines[-3:])
if closes[i] < three_line_low:
lines.append({'high': last_line['low'], 'low': closes[i],
'color': 'black'})
else: # black
if closes[i] < last_line['low']:
lines.append({'high': last_line['low'], 'low': closes[i],
'color': 'black'})
elif len(lines) >= 3:
three_line_high = max(l['high'] for l in lines[-3:])
if closes[i] > three_line_high:
lines.append({'high': closes[i], 'low': last_line['high'],
'color': 'white'})
return lines
def three_line_break_signal(lines: list) -> str:
"""检测turnaround线(反转信号)。"""
if len(lines) < 2:
return 'NEUTRAL'
if lines[-1]['color'] == 'white' and lines[-2]['color'] == 'black':
return 'BUY' # 白turnaround线
elif lines[-1]['color'] == 'black' and lines[-2]['color'] == 'white':
return 'SELL' # 黑turnaround线
return 'HOLD_CURRENT'
def generate_renko(closes: list, brick_size: float) -> list:
"""从收盘价生成砖块图。"""
if len(closes) < 1 or brick_size <= 0:
return []
bricks = []
base_price = closes[0]
for price in closes[1:]:
while price >= base_price + brick_size:
bricks.append({'bottom': base_price, 'top': base_price + brick_size,
'color': 'white'})
base_price += brick_size
while price <= base_price - brick_size:
bricks.append({'bottom': base_price - brick_size, 'top': base_price,
'color': 'black'})
base_price -= brick_size
return bricks
def renko_signal(bricks: list) -> str:
if len(bricks) < 2:
return 'NEUTRAL'
if bricks[-1]['color'] == 'white' and bricks[-2]['color'] == 'black':
return 'BUY'
elif bricks[-1]['color'] == 'black' and bricks[-2]['color'] == 'white':
return 'SELL'
return 'HOLD_CURRENT'
def generate_kagi(closes: list, reversal_amount: float) -> list:
"""
生成锚形图数据。
返回段列表:{'start', 'end', 'direction', 'thickness'}
thickness: 'yang'(粗)或'yin'(细)
"""
if len(closes) < 2:
return []
segments = []
direction = 'up' if closes[1] > closes[0] else 'down'
current_start = closes[0]
current_end = closes[1]
thickness = 'yang' if direction == 'up' else 'yin'
prior_high = max(closes[0], closes[1])
prior_low = min(closes[0], closes[1])
for price in closes[2:]:
if direction == 'up':
if price > current_end:
current_end = price # 延伸线
if price > prior_high:
thickness = 'yang' # 突破先前高点 -> 粗
prior_high = price
elif current_end - price >= reversal_amount:
# 反转:保存当前段,开始新的下行段
segments.append({'start': current_start, 'end': current_end,
'direction': direction, 'thickness': thickness})
current_start = current_end
current_end = price
direction = 'down'
if price < prior_low:
thickness = 'yin'
prior_low = price
else: # down
if price < current_end:
current_end = price
if price < prior_low:
thickness = 'yin'
prior_low = price
elif price - current_end >= reversal_amount:
segments.append({'start': current_start, 'end': current_end,
'direction': direction, 'thickness': thickness})
current_start = current_end
current_end = price
direction = 'up'
if price > prior_high:
thickness = 'yang'
prior_high = price
# 添加最后段
segments.append({'start': current_start, 'end': current_end,
'direction': direction, 'thickness': thickness})
return segments
def kagi_trend_filter(segments: list) -> str:
"""使用锚形厚度作为二元趋势过滤器。"""
if not segments:
return 'NEUTRAL'
if segments[-1]['thickness'] == 'yang':
return 'BULLISH_ONLY' # 仅从蜡烛图信号做多
else:
return 'BEARISH_ONLY' # 仅做空或观望
"使用蜡烛图——或任何其他技术工具——的最重要规则是在先前技术图形的背景下使用蜡烛信号。" "蜡烛图不会将亏损交易者转变为盈利交易者。要取得成功,必须将蜡烛图与其他技术工具结合使用。"