基于价格行为的打板策略代码:手把手教你用QMT实现涨停板捕捉

adminadmin 精选技术文档 2025-09-27 668 0

大家好!今天我要和大家分享一个基于价格行为的打板策略,专门捕捉那些强势涨停的股票。这个策略结合了价格、成交量和大单行为等多个维度,帮你提高打板的成功率。

一、策略核心逻辑

我们的打板策略有四个"硬核"条件,缺一不可:

  1. 价格触及涨停 - 股价必须达到当天的涨停价

  2. 早盘快速封板 - 必须在10:30之前封住涨停

  3. 成交量显著放大 - 当天成交量要是5日均量的2倍以上

  4. 大单封板 - 买一量是卖一量的10倍,且封单金额超过500万

这些条件组合起来,能帮我们筛选出真正有实力的涨停板,而不是那种半死不活的封板。

def calculate_limit_up_price(current_price, is_st=False, is_new_stock=False):
    """
    精确计算涨停价,避免浮点误差
    :param current_price: 当前价格
    :param is_st: 是否ST股票
    :param is_new_stock: 是否新股(无涨跌幅限制)
    :return: 涨停价(精确到分)
    """
    if is_new_stock:
        return None  # 新股无涨跌幅限制,不适用此策略
    
    if is_st:
        limit_ratio = 0.05  # ST股票5%涨跌幅
    else:
        limit_ratio = 0.10  # 普通股票10%涨跌幅(主板)
        # 注意:创业板/科创板是20%,这里简化处理,实际应根据市场区分
    
    limit_up_price = round(current_price * (1 + limit_ratio) / 0.01) * 0.01
    return limit_up_price
def check_limit_up_strategy(stock_data, market_data):
    """
    检查是否满足打板策略条件
    :param stock_data: 股票基本信息
    :param market_data: 实时市场数据
    :return: 是否满足条件 (bool), 原因说明 (str)
    """
    try:
        # 基础检查:排除特殊情况
        if stock_data.is_new_stock or stock_data.is_suspended:
            return False, "新股或停牌股,跳过"
            
        if stock_data.is_st:
            limit_ratio = 0.05
        else:
            limit_ratio = 0.10  # 主板10%,创业板科创板需特殊处理
            
        # 1. 检查价格触及涨停
        current_price = market_data.last_price
        limit_up_price = calculate_limit_up_price(current_price, stock_data.is_st, stock_data.is_new_stock)
        
        if limit_up_price is None:
            return False, "新股无涨跌幅限制"
            
        price_diff = abs(current_price - limit_up_price)
        if price_diff > 0.01:  # 允许1分钱误差
            return False, f"未触及涨停,当前{current_price},涨停{limit_up_price}"
        
        # 2. 检查早盘快速封板(10:30前)
        current_time = market_data.current_time
        if current_time.hour > 10 or (current_time.hour == 10 and current_time.minute >= 30):
            return False, f"非早盘封板,当前时间{current_time.strftime('%H:%M')}"
        
        # 3. 检查成交量显著放大(2倍于5日均量)
        current_volume = market_data.volume
        avg_5_volume = market_data.avg_5_volume
        
        if avg_5_volume == 0:  # 避免除零错误
            return False, "5日均量数据异常"
            
        volume_ratio = current_volume / avg_5_volume
        if volume_ratio < 2:
            return False, f"成交量不足,当前{volume_ratio:.1f}倍5日均量,要求2倍"
        
        # 4. 检查大单封板
        buy1_volume = market_data.buy1_volume
        sell1_volume = market_data.sell1_volume
        buy1_price = market_data.buy1_price
        sell1_price = market_data.sell1_price
        
        # 确保买一价就是涨停价
        if abs(buy1_price - limit_up_price) > 0.01:
            return False, f"买一价不是涨停价,买一{buy1_price},涨停{limit_up_price}"
        
        if sell1_volume == 0:  # 避免除零错误
            sell1_volume = 0.0001  # 极小值避免除零
            
        buy_sell_ratio = buy1_volume / sell1_volume
        if buy_sell_ratio < 10:
            return False, f"买一卖一比不足,当前{buy_sell_ratio:.1f}倍,要求10倍"
        
        # 计算封单金额(买一价 * 买一量)
        limit_order_amount = buy1_price * buy1_volume
        if limit_order_amount < 5000000:  # 500万
            return False, f"封单金额不足,当前{limit_order_amount/10000:.1f}万,要求500万"
        
        # 所有条件都满足!
        reason = f"涨停({current_price:.2f}),早盘({current_time.strftime('%H:%M')}), " \
                f"量比{volume_ratio:.1f}, 买一卖一比{buy_sell_ratio:.1f}, 封单{limit_order_amount/10000:.1f}万"
        return True, reason
        
    except Exception as e:
        # 异常处理很重要,避免策略因异常中断
        error_msg = f"策略检查异常: {str(e)}"
        print(error_msg)
        return False, error_msg

重要提醒

  1. 创业板/科创板注意:20%涨跌幅的股票,涨停价计算要调整 limit_ratio = 0.20

  2. 新股风险:新股没有涨跌幅限制,这个策略不适用

  3. 停牌股票:一定要排除停牌股票,避免无效操作

  4. 封单阈值:500万封单金额对大盘股可能太低,对小盘股可能太高,需要动态调整


版权声明

本文仅代表作者观点,不代表牛人量化交易网立场。
本文系作者授权牛人量化交易网发表,未经许可,不得转载。

喜欢0发布评论

评论列表

发表评论

  • 昵称(必填)
  • 邮箱
  • 网址