def handle_bar(context, bar_dict):
prices = history_bars(context.s1, context.LONGPERIOD + 1, '1h', 'close')
short_avg = talib.SMA(prices, context.SHORTPERIOD)
long_avg = talib.SMA(prices, context.LONGPERIOD)
cur_position = context.portfolio.positions[context.s1].quantity
shares = context.portfolio.cash / bar_dict[context.s1].close
if short_avg[-1] < long_avg[-1] and short_avg[-2] > long_avg[-2] and cur_position > 0:
order_target_value(context.s1, 0)
if short_avg[-1] > long_avg[-1] and short_avg[-2] < long_avg[-2]:
order_shares(context.s1, shares)
strategy_1h.py 文件源码
python
阅读 18
收藏 0
点赞 0
评论 0
评论列表
文章目录