请到后台主题设置添加
首页 / 未命名

用DeepSeek结合主力试盘站稳均线编写顶级游资黄金法则程序

以下是一个结合主力试盘、站稳均线和洗盘特征的量化交易策略示例,采用Python编写。该策略通过多维度技术指标组合来识别主力资金动向:

“`python

import pandas as pd

import numpy as np

import talib

import matplotlib.pyplot as plt

def calculate_technical_indicators(df):

# 均线系统

df[‘MA5’] = talib.MA(df[‘close’], timeperiod=5)

df[‘MA10’] = talib.MA(df[‘close’], timeperiod=10)

df[‘MA20’] = talib.MA(df[‘close’], timeperiod=20)

# 量能指标

df[‘VOL_MA5’] = talib.MA(df[‘volume’], timeperiod=5)

# 波动指标

df[‘ATR’] = talib.ATR(df[‘high’], df[‘low’], df[‘close’], timeperiod=14)

# K线形态识别

df[‘UPPER_SHADOW’] = (df[‘high’] – np.maximum(df[‘open’], df[‘close’])) / df[‘high’] * 100

df[‘LOWER_SHADOW’] = (np.minimum(df[‘open’], df[‘close’]) – df[‘low’]) / df[‘low’] * 100

return df

def detect_main_actions(df):

# 主力试盘特征:长上影线+量能放大

df[‘TEST_SIGNAL’] = np.where(

(df[‘UPPER_SHADOW’] > 3) &

(df[‘volume’] > df[‘VOL_MA5’] * 1.5), 1, 0)

# 洗盘特征:价格震荡+量能持续

df[‘WASH_SIGNAL’] = np.where(

(df[‘close’].rolling(5).std()/df[‘MA20’] > 0.03) &

(df[‘volume’] > df[‘VOL_MA5’] * 1.2).rolling(3).sum() >= 2, 1, 0)

# 站稳均线:价格连续3日站上5日线且均线多头排列

df[‘MA_SIGNAL’] = np.where(

(df[‘close’] > df[‘MA5’]) &

(df[‘MA5’] > df[‘MA10’]) &

(df[‘MA10’] > df[‘MA20’]) &

(df[‘close’].shift(1) > df[‘MA5’].shift(1)) &

(df[‘close’].shift(2) > df[‘MA5’].shift(2)), 1, 0)

return df

def generate_signals(df):

# 综合买入信号

df[‘BUY_SIGNAL’] = np.where(

(df[‘TEST_SIGNAL’].shift(3) == 1) & # 3日前出现试盘

(df[‘WASH_SIGNAL’].rolling(5).sum() >= 2) & # 近期出现洗盘

(df[‘MA_SIGNAL’] == 1), 1, 0) # 当前站稳均线

# 卖出信号:跌破5日线或盈利超过15%

df[‘SELL_SIGNAL’] = np.where(

(df[‘close’] < df[‘MA5’]) |

(df[‘close’] / df[‘entry_price’] > 1.15), 1, 0)

return df

def plot_results(df):

plt.figure(figsize=(16, 12))

ax1 = plt.subplot(311)

plt.plot(df[‘close’], label=’Price’)

plt.plot(df[‘MA5′], label=’5MA’)

plt.plot(df[‘MA10′], label=’10MA’)

plt.scatter(df[df[‘BUY_SIGNAL’]==1].index,

df[df[‘BUY_SIGNAL’]==1][‘close’], marker=’^’, color=’g’, s=100)

plt.scatter(df[df[‘SELL_SIGNAL’]==1].index,

df[df[‘SELL_SIGNAL’]==1][‘close’], marker=’v’, color=’r’, s=100)

plt.legend()

ax2 = plt.subplot(312)

plt.bar(df.index, df[‘volume’], color=np.where(df[‘close’]>df[‘open’], ‘g’, ‘r’))

plt.plot(df[‘VOL_MA5′], label=’5日平均成交量’)

plt.legend()

ax3 = plt.subplot(313)

plt.plot(df[‘UPPER_SHADOW’], label=’上影线比例’)

plt.plot(df[‘LOWER_SHADOW’], label=’下影线比例’)

plt.legend()

plt.show()

# 使用示例

if __name__ == “__main__”:

# 加载数据(示例数据需要包含OHLCV数据)

df = pd.read_csv(‘stock_data.csv’)

df = calculate_technical_indicators(df)

df = detect_main_actions(df)

df = generate_signals(df)

plot_results(df)

“`

核心逻辑说明:

1. 主力试盘识别:

– 长上影线(超过3%)

– 伴随成交量放大(超过5日均量1.5倍)

2. 洗盘阶段特征:

– 价格波动率增加(5日标准差超过3%)

– 持续放量(3日内有2天量能超过5日均量)

3. 趋势确认条件:

– 均线多头排列(5>10>20)

– 连续3日站稳5日均线

4. 买卖信号生成:

– 买入:试盘信号出现后,经过洗盘阶段并站稳均线

– 卖出:跌破5日线或盈利达到15%

优化方向建议:

1. 增加市场情绪指标(如涨停板数量、板块效应)

2. 结合Level2数据(委托队列、大单跟踪)

3. 加入波动率过滤条件(排除市场极端情况)

4. 优化参数组合(通过遗传算法或网格搜索)

注意事项:

– 需配合严格风险控制(建议单笔交易不超过2%仓位)

– 需进行多周期、多品种的回测验证

– 盘中需监控异常量价关系(如钓鱼线、脉冲波)

此策略结合了主力行为分析的经典理论,但实际应用中需根据具体品种特征进行调整,建议先用模拟盘验证后再实盘操作。

版权说明:
1.版权归本网站或原作者所有;
2.未经本网或原作者允许不得转载本文内容,否则将视为侵权;
3.转载或者引用本文内容请注明来源及原作者;
4.对于不遵守此声明或者其他违法使用本文内容者,本人依法保留追究权等。
搜索
最新留言
关注我们
关注我们
微信
关注我们
微博
请到后台主题设置添加

Powered ByZ-Blog.