# 导入函数库
import jqdata
'''
每股营业利润作为alpha因子,每周一换仓,选在21日均线之上的前30名股票买入;
在dkx金叉且21日均线上买入,dkx死叉或21日均线下穿卖出
'''
# 策略初始化
def initialize(context):
g.security = get_index_stocks('000300.XSHG')#股票池
set_option('use_real_price',True)#价格前复权
set_benchmark('000300.XSHG')
set_order_cost(OrderCost(open_tax=0,close_tax=0.001, open_commission=0.0003, close_commission=0.0003,min_commission=5), type='stock')
def handle_data(context,data):
tobuy=[]
for stock in g.security:
p = get_current_data()[stock].day_open
amount = context.portfolio.positions[stock].total_amount
cost= context.portfolio.positions[stock].avg_cost
if amount>0 and p>= cost*1.25:
order_target(stock,0) #止盈
if amount>0 and p<=cost*0.9:
order_target(stock,0)#止损
if p<&#
小市值 止盈止损
最新推荐文章于 2022-01-10 16:14:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)