TrailingStop.py 文件源码

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

项目:bigfishtrader 作者: xingetouzi 项目源码 文件源码
def entry(context, data, s, lot=LOT):
    def order_to(n):
        sod = context.stop_order.pop(s, None)
        # cancel_order(sod.id)
        if sod:
            o = get_order(sod)
            if o.is_open:
                o.cancel()
                n *= 2
        order(s, n)
        # cancel former stop_order

    dc = data.history(s, fields="close", length=MA_SLOW_LEN).values
    ma_fast = context.ma_fast[s]
    ma_slow = context.ma_slow[s]
    ma_fast[0] = ma_fast[1]
    ma_slow[0] = ma_slow[1]
    try:
        ma_fast[1] = ta.MA(dc, MA_FAST_LEN)[-1]
        ma_slow[1] = ta.MA(dc, MA_SLOW_LEN)[-1]
    except:
        return
    if ma_fast[0] <= ma_slow[0] and ma_fast[1] > ma_slow[1]:
        order_to(lot)
    elif ma_fast[0] >= ma_slow[0] and ma_fast[1] < ma_slow[1]:
        order_to(-lot)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号