macd.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:InplusTrader_Linux 作者: zhengwsh 项目源码 文件源码
def handle_bar(context, bar_dict):
    # ?????????????

    # bar_dict[order_book_id] ?????????bar??
    # context.portfolio ???????????????

    # ??order_shares(id_or_ins, amount)??????

    # TODO: ??????????

    # ?????????sma??????????????????????ema????????????????????????????
    prices = history_bars(context.s1, context.OBSERVATION,'1d','close')

    # ?Talib??MACD?????????????????macd, signal ? hist
    macd, signal, hist = talib.MACD(prices, context.SHORTPERIOD,
                                    context.LONGPERIOD, context.SMOOTHPERIOD)

    plot("macd", macd[-1])
    plot("macd signal", signal[-1])

    # macd ?????????signal?macd??????macd?????????????????macd???signal??????

    # ??macd??????macd_signal

    if macd[-1] - signal[-1] < 0 and macd[-2] - signal[-2] > 0:
        # ????portfolio??????
        curPosition = context.portfolio.positions[context.s1].quantity
        #????
        if curPosition > 0:
            order_target_value(context.s1, 0)

    # ????????????????????
    if macd[-1] - signal[-1] > 0 and macd[-2] - signal[-2] < 0:
        # ????
        order_target_percent(context.s1, 1)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号