Pharos
TAMath ops

MININDEX - 最小值索引

函数说明

返回指定周期内最小值的索引位置(距离当前位置的K线数)。

语法

python
result = TA.MININDEX(records, timeperiod)

参数

参数名类型说明
recordsarrayK线数组或数值数组
timeperiodint时间周期

返回值

返回最小值索引数组,值为0到timeperiod-1的整数,表示最小值距离当前的位置

计算方法

在过去timeperiod个数据中,找到最小值的位置,返回其距离当前位置的偏移量

使用场景

  1. 识别近期低点位置
  2. 支撑位确认
  3. 反弹力度分析
  4. 底部形态判断

基础示例

python
def main():
    records = exchange.GetRecords()
    if len(records) < 20:
        return
    
    lows = [r['Low'] for r in records]
    
    # 找到过去20根K线中最低价的位置
    min_idx = TA.MININDEX(lows, 20)
    
    # 最新值
    bars_since_low = min_idx[-1]
    
    Log(f"最低点出现在 {bars_since_low} 根K线之前")
    
    if bars_since_low == 0:
        Log("刚创新低!")
    elif bars_since_low < 5:
        Log("接近低点")
    else:
        Log(f"已经{bars_since_low}根K线未创新低(底部可能形成)")

高级应用

1. 支撑位确认

python
def support_level_detection():
    records = exchange.GetRecords()
    lows = [r['Low'] for r in records[-50:]]
    closes = [r['Close'] for r in records[-50:]]
    
    # 找到20周期最低点
    period = 20
    min_idx = TA.MININDEX(lows, period)[-1]
    
    # 最低点价格
    support_price = lows[-min_idx - 1] if min_idx > 0 else lows[-1]
    current_price = closes[-1]
    
    # 支撑位有效性判断
    if min_idx >= 5 and min_idx <= 15:
        # 低点不太远也不太近
        distance_pct = (current_price - support_price) / support_price * 100
        
        Log(f"支撑位: {support_price:.2f}")
        Log(f"距离支撑: {distance_pct:.2f}%")
        
        if distance_pct < 2:
            Log("正在测试支撑位!")
            return support_price, "TESTING"
        elif distance_pct < 5:
            Log("接近支撑位")
            return support_price, "NEAR"
    
    elif min_idx == 0:
        Log("创新低,支撑失效")
        return support_price, "BROKEN"
    
    return None, None

2. 反弹强度分析

python
def bounce_strength():
    records = exchange.GetRecords()
    lows = [r['Low'] for r in records[-30:]]
    closes = [r['Close'] for r in records[-30:]]
    
    # 找到最低点位置
    min_idx = TA.MININDEX(lows, 30)[-1]
    
    if min_idx == 0:
        Log("当前在最低点,无反弹")
        return 0
    
    # 计算反弹幅度
    bottom_price = lows[-min_idx - 1]
    current_price = closes[-1]
    bounce_pct = (current_price - bottom_price) / bottom_price * 100
    
    Log(f"距离低点 {min_idx} 根K线")
    Log(f"反弹幅度: {bounce_pct:.2f}%")
    
    # 判断反弹性质
    if bounce_pct > 10 and min_idx >= 5:
        Log("强劲反弹")
        return "STRONG"
    elif bounce_pct > 5:
        Log("温和反弹")
        return "MODERATE"
    elif bounce_pct > 2:
        Log("弱反弹")
        return "WEAK"
    else:
        Log("几乎无反弹")
        return "NONE"

3. 底部形态识别

python
def bottom_pattern():
    records = exchange.GetRecords()
    lows = [r['Low'] for r in records[-50:]]
    
    # 使用不同周期
    short_min_idx = TA.MININDEX(lows, 10)[-1]
    mid_min_idx = TA.MININDEX(lows, 20)[-1]
    long_min_idx = TA.MININDEX(lows, 50)[-1]
    
    # 双底特征:短中期低点接近,但不是同一个
    if 5 <= short_min_idx <= 10 and 8 <= mid_min_idx <= 15:
        first_low = lows[-mid_min_idx - 1]
        recent_low = lows[-short_min_idx - 1]
        
        # 两个低点价格接近(差异<3%)
        if abs(first_low - recent_low) / first_low < 0.03:
            Log("可能形成双底形态")
            Log(f"第一低点在{mid_min_idx}根K线前: {first_low}")
            Log(f"第二低点在{short_min_idx}根K线前: {recent_low}")
            return "DOUBLE_BOTTOM"
    
    # V型底:快速创新低后快速反弹
    if long_min_idx >= 10 and long_min_idx <= 20 and short_min_idx > 5:
        Log("可能是V型底反转")
        return "V_BOTTOM"
    
    return None

4. 做多时机判断

python
def long_entry_timing():
    records = exchange.GetRecords()
    lows = [r['Low'] for r in records[-30:]]
    closes = [r['Close'] for r in records[-30:]]
    
    # 找到近期低点
    min_idx = TA.MININDEX(lows, 30)[-1]
    
    # 理想做多时机:低点后3-8根K线
    if 3 <= min_idx <= 8:
        bottom = lows[-min_idx - 1]
        current = closes[-1]
        bounce = (current - bottom) / bottom * 100
        
        # 反弹3-7%是理想进场区间
        if 3 <= bounce <= 7:
            Log(f"理想做多时机!")
            Log(f"底部后{min_idx}根K线,反弹{bounce:.1f}%")
            return True
    
    # 过早(刚创新低)
    elif min_idx <= 2:
        Log("刚创新低,等待企稳")
        return False
    
    # 过晚(反弹太多)
    elif min_idx > 12:
        Log("反弹过高,等待回调")
        return False
    
    return None

5. 趋势反转信号

python
def trend_reversal():
    records = exchange.GetRecords()
    lows = [r['Low'] for r in records[-100:]]
    
    # 多周期分析
    min_idx_20 = TA.MININDEX(lows, 20)[-1]
    min_idx_50 = TA.MININDEX(lows, 50)[-1]
    min_idx_100 = TA.MININDEX(lows, 100)[-1]
    
    # 底部反转信号:所有周期的低点都较远
    if min_idx_20 > 10 and min_idx_50 > 20 and min_idx_100 > 30:
        Log("长期未创新低,可能底部反转")
        return "REVERSAL_UP"
    
    # 持续下跌:短周期不断创新低
    elif min_idx_20 <= 3:
        Log("持续创新低,下跌趋势延续")
        return "CONTINUE_DOWN"
    
    # 筑底中:中期低点较远,短期在振荡
    elif min_idx_20 < 10 and min_idx_50 > 15:
        Log("可能在筑底")
        return "BOTTOMING"
    
    return "NEUTRAL"

注意事项

  • 返回值是索引(0表示当前位置)
  • 访问具体值:array[-index-1]
  • Python替代:min_idx = lows.index(min(lows[-period:]))
  • 多个最小值时返回最近的那个

相关函数