You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python函数计算Support Break等指标全返回False问题排查

所有指标结果全为False的原因及修正方案

一、窗口参数与数据长度不匹配

你设置的默认参数left_bars=15、right_bars=15,计算支撑/阻力时用到的滚动窗口大小是15+15+1=31,但测试用的close_data只有10个数据点。滚动窗口大于数据长度时,rolling.max()和rolling.min()会返回全NaN,后续所有基于支撑/阻力位的条件判断都无法成立,直接导致所有指标为False。

修正:测试时缩小窗口参数,让窗口大小适配数据长度:

support_resistance_levels, result_df = calculate_support_resistance_slope(close_data, left_bars=2, right_bars=2)

二、支撑/阻力突破的逻辑错误

  1. 支撑突破(Support Break):原条件中close_data.shift(1) >= high_use_pivot.shift(1)逻辑错误,支撑突破应是前一根K线收盘价在支撑位之上,当前K线收盘价跌破支撑位,正确条件为close_data.shift(1) >= low_use_pivot.shift(1)。
  2. 阻力突破(Resistance Break):原条件中close_data.shift(1) <= low_use_pivot.shift(1)逻辑错误,阻力突破应是前一根K线收盘价在阻力位之下,当前K线收盘价突破阻力位,正确条件为close_data.shift(1) <= high_use_pivot.shift(1)。

修正后的突破判断代码:

support_breaks = (close_data < low_use_pivot) & (close_data.shift(1) >= low_use_pivot.shift(1)) & (volume_oscillator > volume_thresh)
resistance_breaks = (close_data > high_use_pivot) & (close_data.shift(1) <= high_use_pivot.shift(1)) & (volume_oscillator > volume_thresh)

三、牛/熊 Wick的逻辑矛盾

  1. Bull Wick:原条件(close_data > high_use_pivot) & (close_data - low_use_pivot < 0)完全矛盾——阻力位high_use_pivot必然大于支撑位low_use_pivot,收盘价高于阻力位时,close_data - low_use_pivot肯定为正,第三个条件永远不成立。
  2. Bear Wick:原条件(close_data < low_use_pivot) & (high_use_pivot - close_data < 0)同样矛盾——收盘价低于支撑位时,high_use_pivot - close_data必然为正,第三个条件永远不成立。

修正:删除矛盾条件,重新定义Wick逻辑(示例如下,可根据实际需求调整):

# 牛Wick:当前收盘价突破阻力位,前一根未突破
bull_wicks = (close_data > high_use_pivot) & (close_data.shift(1) <= high_use_pivot.shift(1))
# 熊Wick:当前收盘价跌破支撑位,前一根未跌破
bear_wicks = (close_data < low_use_pivot) & (close_data.shift(1) >= low_use_pivot.shift(1))

四、成交量振荡器的数据源错误

你用close_data计算volume_oscillator,但这个指标应基于成交量数据而非收盘价。误用收盘价会导致振荡器数值不符合volume_thresh=20的阈值要求,进一步让突破条件无法触发。

修正:修改函数参数,传入成交量数据重新计算:

def calculate_support_resistance_slope(close_data, volume_data, left_bars=15, right_bars=15, volume_thresh=20):
    # ... 其他代码 ...
    short_volume = pd.Series(volume_data).ewm(span=5, adjust=False).mean()
    long_volume = pd.Series(volume_data).ewm(span=10, adjust=False).mean()
    volume_oscillator = 100 * (short_volume - long_volume) / long_volume
    # ... 其他代码 ...

调用时传入成交量数据:

close_data = pd.Series([10, 12, 8, 15, 10, 18, 20, 14, 25, 22])
volume_data = pd.Series([200, 300, 150, 400, 250, 500, 600, 350, 700, 450])
support_resistance_levels, result_df = calculate_support_resistance_slope(close_data, volume_data, left_bars=2, right_bars=2)

内容的提问来源于stack exchange,提问作者Rahul

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 11:02:07